make config --add behave correctly for empty and NULL values
commitc8466645edd1413c7efed824f5bddac457eb77f9
authorTanay Abhra <tanayabh@gmail.com>
Mon, 18 Aug 2014 10:17:57 +0000 (18 03:17 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 18 Aug 2014 17:45:59 +0000 (18 10:45 -0700)
tree1e0aa1584d4b7155e56f62bead24136ef54f8cde
parent32f56600bb6ac6fc57183e79d2c1515dfa56672f
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 <tanayabh@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/config.c
config.c
t/t1303-wacky-config.sh