diff --git a/builtin/config.c b/builtin/config.c index 5677c942b6..8224699663 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -599,7 +599,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) check_argc(argc, 2, 2); value = normalize_value(argv[0], argv[1]); return git_config_set_multivar_in_file(given_config_source.file, - argv[0], value, "^$", 0); + argv[0], value, "a^", 0); } else if (actions == ACTION_REPLACE_ALL) { check_write(); diff --git a/config.c b/config.c index 2634457f6b..ffe010423d 100644 --- a/config.c +++ b/config.c @@ -1233,7 +1233,7 @@ static int matches(const char *key, const char *value) return !strcmp(key, store.key) && (store.value_regex == NULL || (store.do_not_match ^ - !regexec(store.value_regex, value, 0, NULL, 0))); + (value && !regexec(store.value_regex, value, 0, NULL, 0)))); } static int store_aux(const char *key, const char *value, void *cb) diff --git a/t/t1303-wacky-config.sh b/t/t1303-wacky-config.sh index 3a2c81968c..3b92083e19 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