summaryrefslogtreecommitdiff
path: root/t/t1300-config.sh
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2018-04-09 08:32:24 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-04-09 12:32:59 (GMT)
commit22aedfccd0cfe7c8f09a990cf4777efc7f27bd2e (patch)
tree9065d747692b570ca27b144796a539d3465e6383 /t/t1300-config.sh
parent6ae996f2acf3ad780b8d338c81e24143f0b0d304 (diff)
downloadgit-22aedfccd0cfe7c8f09a990cf4777efc7f27bd2e.zip
git-22aedfccd0cfe7c8f09a990cf4777efc7f27bd2e.tar.gz
git-22aedfccd0cfe7c8f09a990cf4777efc7f27bd2e.tar.bz2
git config --unset: remove empty sections (in the common case)
The original reasoning for not removing section headers upon removal of the last entry went like this: the user could have added comments about the section, or about the entries therein, and if there were other comments there, we would not know whether we should remove them. In particular, a concocted example was presented that looked like this (and was added to t1300): # some generic comment on the configuration file itself # a comment specific to this "section" section. [section] # some intervening lines # that should also be dropped key = value # please be careful when you update the above variable The ideal thing for `git config --unset section.key` in this case would be to leave only the first line behind, because all the other comments are now obsolete. However, this is unfeasible, short of adding a complete Natural Language Processing module to Git, which seems not only a lot of work, but a totally unreasonable feature (for little benefit to most users). Now, the real kicker about this problem is: most users do not edit their config files at all! In their use case, the config looks like this instead: [section] key = value ... and it is totally obvious what should happen if the entry is removed: the entire section should vanish. Let's generalize this observation to this conservative strategy: if we are removing the last entry from a section, and there are no comments inside that section nor surrounding it, then remove the entire section. Otherwise behave as before: leave the now-empty section (including those comments, even ones about the now-deleted entry). We have to be extra careful to handle the case where more than one entry is removed: any subset of them might be the last entries of their respective sections (and if there are no comments in or around that section, the section should be removed, too). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t1300-config.sh')
-rwxr-xr-xt/t1300-config.sh4
1 files changed, 2 insertions, 2 deletions
diff --git a/t/t1300-config.sh b/t/t1300-config.sh
index 8a3cd2c..92aaa53 100755
--- a/t/t1300-config.sh
+++ b/t/t1300-config.sh
@@ -1390,7 +1390,7 @@ test_expect_success 'urlmatch with wildcard' '
'
# good section hygiene
-test_expect_failure '--unset last key removes section (except if commented)' '
+test_expect_success '--unset last key removes section (except if commented)' '
cat >.git/config <<-\EOF &&
# some generic comment on the configuration file itself
# a comment specific to this "section" section.
@@ -1472,7 +1472,7 @@ test_expect_failure '--unset last key removes section (except if commented)' '
test_line_count = 3 .git/config
'
-test_expect_failure '--unset-all removes section if empty & uncommented' '
+test_expect_success '--unset-all removes section if empty & uncommented' '
cat >.git/config <<-\EOF &&
[section]
key = value1