t1300: add a few more hairy examples of sections becoming empty

During the review of the first iteration of the patch series to remove sections that become empty upon --unset or --unset-all, Jeff King identified a couple of problematic cases with the backtracking approach that was still used then to "look backwards for the section header": https://public-inbox.org/git/20180329213229.GG2939@sigill.intra.peff.net/ This patch adds a couple of concocted examples designed to fool a backtracking parser. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Apr 9, 2018 at 10:31 UTC 422e8ef26d35a7e54d5b7b990669f4a525cb8828
1 file changed +44 -1
t/t1300-config.sh
+44 -1
@@ -1426,7 +1426,50 @@ test_expect_failure '--unset last key removes section (except if commented)' '
1426 EOF
1427
1428 git config --unset section.key &&
1429 - test_cmp expect .git/config
1429 + test_cmp expect .git/config &&
1430 +
1431 + q_to_tab >.git/config <<-\EOF &&
1432 + [one]
1433 + Qkey = "multiline \
1434 + QQ# with comment"
1435 + [two]
1436 + key = true
1437 + EOF
1438 + git config --unset two.key &&
1439 + ! grep two .git/config &&
1440 +
1441 + q_to_tab >.git/config <<-\EOF &&
1442 + [one]
1443 + Qkey = "multiline \
1444 + QQ# with comment"
1445 + [one]
1446 + key = true
1447 + EOF
1448 + git config --unset-all one.key &&
1449 + test_line_count = 0 .git/config &&
1450 +
1451 + q_to_tab >.git/config <<-\EOF &&
1452 + [one]
1453 + Qkey = true
1454 + Q# a comment not at the start
1455 + [two]
1456 + Qkey = true
1457 + EOF
1458 + git config --unset two.key &&
1459 + grep two .git/config &&
1460 +
1461 + q_to_tab >.git/config <<-\EOF &&
1462 + [one]
1463 + Qkey = not [two "subsection"]
1464 + [two "subsection"]
1465 + [two "subsection"]
1466 + Qkey = true
1467 + [TWO "subsection"]
1468 + [one]
1469 + EOF
1470 + git config --unset two.subsection.key &&
1471 + test "not [two subsection]" = "$(git config one.key)" &&
1472 + test_line_count = 3 .git/config
1473 '
1474
1475 test_expect_failure 'adding a key into an empty section reuses header' '