From c8466645edd1413c7efed824f5bddac457eb77f9 Mon Sep 17 00:00:00 2001 From: Tanay Abhra Date: Mon, 18 Aug 2014 03:17:57 -0700 Subject: make config --add behave correctly for empty and NULL values Currently if we have a config file like, [foo] baz bar = and we try something like, "git config --add foo.baz roll", Git will segfault. Moreover, for "git config --add foo.bar roll", it will overwrite the original value instead of appending after the existing empty value. The problem lies with the regexp used for simulating --add in `git_config_set_multivar_in_file()`, "^$", which in ideal case should not match with any string but is true for empty strings. Instead use a regexp like "a^" which can not be true for any string, empty or not. For removing the segfault add a check for NULL values in `matches()` in config.c. Signed-off-by: Tanay Abhra Signed-off-by: Junio C Hamano --- t/t1303-wacky-config.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 't/t1303-wacky-config.sh') diff --git a/t/t1303-wacky-config.sh b/t/t1303-wacky-config.sh index 3a2c81968..3b92083e1 100755 --- a/t/t1303-wacky-config.sh +++ b/t/t1303-wacky-config.sh @@ -111,4 +111,24 @@ test_expect_success 'unset many entries' ' test_must_fail git config section.key ' +test_expect_success '--add appends new value after existing empty value' ' + cat >expect <<-\EOF && + + + fool + roll + EOF + cp .git/config .git/config.old && + test_when_finished "mv .git/config.old .git/config" && + cat >.git/config <<-\EOF && + [foo] + baz + baz = + baz = fool + EOF + git config --add foo.baz roll && + git config --get-all foo.baz >output && + test_cmp expect output +' + test_done -- cgit v1.2.1