branch: add test for -m renaming multiple config sections

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Jun 18, 2017 at 23:17 UTC c8b2cec09e548df7c948e5f4453381f0a3b0f6a9
1 file changed +41
t/t3200-branch.sh
+41
@@ -341,6 +341,47 @@ test_expect_success 'config information was renamed, too' '
341 test_must_fail git config branch.s/s.dummy
342 '
343
344 +test_expect_success 'git branch -m correctly renames multiple config sections' '
345 + test_when_finished "git checkout master" &&
346 + git checkout -b source master &&
347 +
348 + # Assert that a config file with multiple config sections has
349 + # those sections preserved...
350 + cat >expect <<-\EOF &&
351 + branch.dest.key1=value1
352 + some.gar.b=age
353 + branch.dest.key2=value2
354 + EOF
355 + cat >config.branch <<\EOF &&
356 +;; Note the lack of -\EOF above & mixed indenting here. This is
357 +;; intentional, we are also testing that the formatting of copied
358 +;; sections is preserved.
359 +
360 +;; Comment for source. Tabs
361 +[branch "source"]
362 + ;; Comment for the source value
363 + key1 = value1
364 +;; Comment for some.gar. Spaces
365 +[some "gar"]
366 + ;; Comment for the some.gar value
367 + b = age
368 +;; Comment for source, again. Mixed tabs/spaces.
369 +[branch "source"]
370 + ;; Comment for the source value, again
371 + key2 = value2
372 +EOF
373 + cat config.branch >>.git/config &&
374 + git branch -m source dest &&
375 + git config -f .git/config -l | grep -F -e source -e dest -e some.gar >actual &&
376 + test_cmp expect actual &&
377 +
378 + # ...and that the comments for those sections are also
379 + # preserved.
380 + cat config.branch | sed "s/\"source\"/\"dest\"/" >expect &&
381 + sed -n -e "/Note the lack/,\$p" .git/config >actual &&
382 + test_cmp expect actual
383 +'
384 +
385 test_expect_success 'deleting a symref' '
386 git branch target &&
387 git symbolic-ref refs/heads/symref refs/heads/target &&