Skip to content

Commit db4eca1

Browse files
jrngitster
authored andcommitted
clone: handle empty config values in -c
"git clone --config" uses the following incantation to add an item to a config file, instead of replacing an existing value: git_config_set_multivar_gently(key, value, "^$", 0) As long as no existing value matches the regex ^$, that works as intended and adds to the config. When a value is empty, though, it replaces the existing value. Noticed while trying to set credential.helper during a clone to use a specific helper without inheriting from ~/.gitconfig and /etc/gitconfig. That is, I ran git clone -c credential.helper= \ -c credential.helper=myhelper \ https://example.com/repo intending to produce the configuration [credential] helper = helper = myhelper Without this patch, the 'helper =' line is not included and the credential helper from /etc/gitconfig gets used. Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3b9e3c2 commit db4eca1

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

builtin/clone.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,9 @@ static int checkout(int submodule_progress)
755755

756756
static int write_one_config(const char *key, const char *value, void *data)
757757
{
758-
return git_config_set_multivar_gently(key, value ? value : "true", "^$", 0);
758+
return git_config_set_multivar_gently(key,
759+
value ? value : "true",
760+
CONFIG_REGEX_NONE, 0);
759761
}
760762

761763
static void write_config(struct string_list *config)

t/t5611-clone-config.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ test_expect_success 'clone -c can set multi-keys' '
1919
test_cmp expect actual
2020
'
2121

22+
test_expect_success 'clone -c can set multi-keys, including some empty' '
23+
rm -rf child &&
24+
git clone -c credential.helper= -c credential.helper=hi . child &&
25+
printf "%s\n" "" hi >expect &&
26+
git --git-dir=child/.git config --get-all credential.helper >actual &&
27+
test_cmp expect actual
28+
'
29+
2230
test_expect_success 'clone -c without a value is boolean true' '
2331
rm -rf child &&
2432
git clone -c core.foo . child &&

0 commit comments

Comments
 (0)