Skip to content

Commit 53ca053

Browse files
peffgitster
authored andcommitted
t1300: document some aesthetic failures of the config editor
The config-editing code used by "git config var value" is built around the regular config callback parser, whose only triggerable item is an actual key. As a result, it does not know anything about section headers, which can result in unnecessarily ugly output: 1. When we delete the last key in a section, we should be able to delete the section header. 2. When we add a key into a section, we should be able to reuse the same section header, even if that section did not have any keys in it already. Unfortunately, fixing these is not trivial with the current code. It would involve the config parser recording and passing back information on each item it finds, including headers, keys, and even comments (or even better, generating an actual in-memory parse-tree). Since these behaviors do not cause any functional problems (i.e., the resulting config parses as expected, it is just uglier than one would like), fixing them can wait until somebody feels like substantially refactoring the parsing code. In the meantime, let's document them as known issues with some tests. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 631bc94 commit 53ca053

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

t/t1300-repo-config.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,4 +1087,39 @@ test_expect_success 'barf on incomplete string' '
10871087
grep " line 3 " error
10881088
'
10891089

1090+
# good section hygiene
1091+
test_expect_failure 'unsetting the last key in a section removes header' '
1092+
cat >.git/config <<-\EOF &&
1093+
# some generic comment on the configuration file itself
1094+
# a comment specific to this "section" section.
1095+
[section]
1096+
# some intervening lines
1097+
# that should also be dropped
1098+
1099+
key = value
1100+
# please be careful when you update the above variable
1101+
EOF
1102+
1103+
cat >expect <<-\EOF &&
1104+
# some generic comment on the configuration file itself
1105+
EOF
1106+
1107+
git config --unset section.key &&
1108+
test_cmp expect .git/config
1109+
'
1110+
1111+
test_expect_failure 'adding a key into an empty section reuses header' '
1112+
cat >.git/config <<-\EOF &&
1113+
[section]
1114+
EOF
1115+
1116+
q_to_tab >expect <<-\EOF &&
1117+
[section]
1118+
Qkey = value
1119+
EOF
1120+
1121+
git config section.key value
1122+
test_cmp expect .git/config
1123+
'
1124+
10901125
test_done

0 commit comments

Comments
 (0)