git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Sahil Dua <sahildua2305@gmail.com>
To: git@vger.kernel.org
Cc: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Junio C Hamano" <gitster@pobox.com>
Subject: [PATCH v2 2/3] branch: add test for -m renaming multiple config sections
Date: Sun, 18 Jun 2017 23:17:50 +0200	[thread overview]
Message-ID: <1497820670-93537-1-git-send-email-sahildua2305@gmail.com> (raw)
In-Reply-To: <0102015ca23f0529-c860f75d-e3bb-48b0-b2c0-502f7ab9d667-000000@eu-west-1.amazonses.com>

From: Ævar Arnfjörð Bjarmason <avarab@gmail.com>

Add a test for how 'git branch -m' handles the renaming of multiple
config sections existing for one branch.

The config format we use is hybrid machine/human editable, and we do
our best to preserve the likes of comments and formatting when editing
the file with git-config.

This adds a test for the currently expected semantics in the face of
some rather obscure edge cases which are unlikely to occur in
practice.

Helped-by: Sahil Dua <sahildua2305@gmail.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Sahil Dua <sahildua2305@gmail.com>
---

Changes
  * Use 'sed -n -e' instead of 'grep -A'.
  * Add mixed indentation for different config sections to
    test that formatting of renamed sections is preserved.

Note (from Avar): I ended up not taking Junio's commentary to use
<<-\EOF with spaces. I think it's important that this codepath be
tested for the exact formatting of the config being preserved, so the
test now does that with more exhaustive checks for the formatting at
the trivial expense of making the test not look like the usual
test idiom.

 t/t3200-branch.sh | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 10f8f02..5eb752c 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -341,6 +341,47 @@ test_expect_success 'config information was renamed, too' '
 	test_must_fail git config branch.s/s.dummy
 '
 
+test_expect_success 'git branch -m correctly renames multiple config sections' '
+	test_when_finished "git checkout master" &&
+	git checkout -b source master &&
+
+	# Assert that a config file with multiple config sections has
+	# those sections preserved...
+	cat >expect <<-\EOF &&
+	branch.dest.key1=value1
+	some.gar.b=age
+	branch.dest.key2=value2
+	EOF
+	cat >config.branch <<\EOF &&
+;; Note the lack of -\EOF above & mixed indenting here. This is
+;; intentional, we are also testing that the formatting of copied
+;; sections is preserved.
+
+;; Comment for source. Tabs
+[branch "source"]
+	;; Comment for the source value
+	key1 = value1
+;; Comment for some.gar. Spaces
+[some "gar"]
+    ;; Comment for the some.gar value
+    b = age
+;; Comment for source, again. Mixed tabs/spaces.
+[branch "source"]
+    ;; Comment for the source value, again
+	key2 = value2
+EOF
+	cat config.branch >>.git/config &&
+	git branch -m source dest &&
+	git config -f .git/config -l | grep -F -e source -e dest -e some.gar >actual &&
+	test_cmp expect actual &&
+
+	# ...and that the comments for those sections are also
+	# preserved.
+	cat config.branch | sed "s/\"source\"/\"dest\"/" >expect &&
+	sed -n -e "/Note the lack/,\$p" .git/config >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'deleting a symref' '
 	git branch target &&
 	git symbolic-ref refs/heads/symref refs/heads/target &&
-- 
2.7.4 (Apple Git-66)


  parent reply	other threads:[~2017-06-18 21:17 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-28 22:56 [PATCH/RFC] branch: add tests for new copy branch feature Sahil Dua
2017-05-28 23:30 ` Ævar Arnfjörð Bjarmason
2017-05-29 20:41   ` Sahil Dua
2017-05-29 20:50     ` Ævar Arnfjörð Bjarmason
2017-05-29 22:23       ` Sahil Dua
2017-06-13 17:55       ` Jonathan Nieder
2017-06-13 18:01         ` Ævar Arnfjörð Bjarmason
2017-06-13 18:08           ` Jonathan Nieder
2017-05-29  2:09 ` Junio C Hamano
2017-05-29 19:39   ` Sahil Dua
2017-05-31 23:35 ` [PATCH/RFC v2 1/6] " Sahil Dua
2017-05-31 23:35   ` [PATCH/RFC v2 4/6] config: modify function signature to include copy argument Sahil Dua
2017-05-31 23:35   ` [PATCH/RFC v2 2/6] branch: add copy branch option Sahil Dua
2017-06-01  1:50     ` Junio C Hamano
2017-06-01 16:09       ` Sahil Dua
2017-05-31 23:35   ` [PATCH/RFC v2 6/6] branch: don't copy or rename config when same branch name Sahil Dua
2017-05-31 23:35   ` [PATCH/RFC v2 3/6] config: abstract out create section from key logic Sahil Dua
2017-05-31 23:35   ` [PATCH/RFC v2 5/6] config: add copy config section logic Sahil Dua
2017-06-01 18:35   ` [PATCH/RFC v3 1/3] branch: add tests for new copy branch feature Sahil Dua
2017-06-01 18:35     ` [PATCH/RFC v3 2/3] config: abstract out create section from key logic Sahil Dua
2017-06-01 18:35     ` [PATCH/RFC v3 3/3] branch: add copy branch feature implementation Sahil Dua
2017-06-01 18:59       ` Ævar Arnfjörð Bjarmason
2017-06-01 22:05         ` Sahil Dua
2017-06-05 20:40     ` [PATCH/RFC v4 1/3] branch: add tests for new copy branch feature Sahil Dua
2017-06-05 20:40       ` [PATCH/RFC v4 2/3] config: abstract out create section from key logic Sahil Dua
2017-06-05 20:40       ` [PATCH/RFC v4 3/3] branch: add copy branch feature implementation Sahil Dua
2017-06-05 20:52         ` Sahil Dua
2017-06-06  0:10           ` Junio C Hamano
2017-06-06  0:14             ` Junio C Hamano
2017-06-06  7:39             ` Ævar Arnfjörð Bjarmason
2017-06-06 10:13               ` Sahil Dua
2017-06-06 12:03               ` Junio C Hamano
2017-06-13 16:17       ` [PATCH 1/3] config: create a function to format section headers Sahil Dua
2017-06-13 16:17         ` [PATCH 3/3] branch: add a --copy (-c) option to go with --move (-m) Sahil Dua
2017-06-13 17:05           ` Junio C Hamano
2017-06-13 17:30             ` Junio C Hamano
2017-06-14  8:01               ` Sahil Dua
2017-06-18 21:19           ` [PATCH v2 " Sahil Dua
2017-06-13 16:17         ` [PATCH 2/3] branch: add test for -m renaming multiple config sections Sahil Dua
2017-06-13 17:10           ` Junio C Hamano
2017-06-13 17:31             ` Ævar Arnfjörð Bjarmason
2017-06-13 17:39               ` Junio C Hamano
2017-06-13 17:53                 ` Ævar Arnfjörð Bjarmason
2017-06-18 21:17           ` Sahil Dua [this message]
2017-06-13 17:06         ` [PATCH 1/3] config: create a function to format section headers Junio C Hamano
2017-06-13 17:09         ` Ævar Arnfjörð Bjarmason
2017-06-18 21:16         ` [PATCH v2 " Sahil Dua
2017-06-19 12:08           ` Ramsay Jones
2017-06-19 14:51             ` Sahil Dua
  -- strict thread matches above, loose matches on Subject: below --
2017-07-05 23:14 [PATCH v2 0/3] branch: add a --copy to go with --move Ævar Arnfjörð Bjarmason
2017-07-05 22:35 ` What's cooking in git.git (Jul 2017, #01; Wed, 5) Junio C Hamano
2017-07-05 23:14   ` [PATCH v2 2/3] branch: add test for -m renaming multiple config sections Ævar Arnfjörð Bjarmason

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1497820670-93537-1-git-send-email-sahildua2305@gmail.com \
    --to=sahildua2305@gmail.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).