fix "git -c" parsing of values with equals signs

If you do something like: git -c core.foo="value with = in it" ... we would split your option on "=" into three fields and throw away the third one. With this patch we correctly take everything after the first "=" as the value (keys cannot have an equals sign in them, so the parsing is unambiguous). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jun 9, 2011 at 11:51 UTC 5bf6529aaa3fa829328ae00ddf7aa851935443b5
2 files changed +7 -1
config.c
+1 -1
@@ -45,7 +45,7 @@ static int git_config_parse_parameter(const char *text,
45 struct strbuf tmp = STRBUF_INIT;
46 struct strbuf **pair;
47 strbuf_addstr(&tmp, text);
48 - pair = strbuf_split(&tmp, '=');
48 + pair = strbuf_split_max(&tmp, '=', 2);
49 if (pair[0]->len && pair[0]->buf[pair[0]->len - 1] == '=')
50 strbuf_setlen(pair[0], pair[0]->len - 1);
51 strbuf_trim(pair[0]);
t/t1300-repo-config.sh
+6
@@ -904,4 +904,10 @@ test_expect_success 'git -c works with aliases of builtins' '
904 test_cmp expect actual
905 '
906
907 +test_expect_success 'git -c does not split values on equals' '
908 + echo "value with = in it" >expect &&
909 + git -c core.foo="value with = in it" config core.foo >actual &&
910 + test_cmp expect actual
911 +'
912 +
913 test_done