Skip to content

Commit 5bf6529

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 28fc3a6 commit 5bf6529

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static int git_config_parse_parameter(const char *text,
4545
struct strbuf tmp = STRBUF_INIT;
4646
struct strbuf **pair;
4747
strbuf_addstr(&tmp, text);
48-
pair = strbuf_split(&tmp, '=');
48+
pair = strbuf_split_max(&tmp, '=', 2);
4949
if (pair[0]->len && pair[0]->buf[pair[0]->len - 1] == '=')
5050
strbuf_setlen(pair[0], pair[0]->len - 1);
5151
strbuf_trim(pair[0]);

t/t1300-repo-config.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,4 +904,10 @@ test_expect_success 'git -c works with aliases of builtins' '
904904
test_cmp expect actual
905905
'
906906

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+
907913
test_done

0 commit comments

Comments
 (0)