Skip to content

Commit d95a07a

Browse files
committed
remote: fix set-branches when no branches are set
To replace the list of branches to be fetched "git remote set-branches" first removes the fetch refspecs for the remote and then creates a new set of fetch refspecs based and the branches passed on the commandline. When deleting the existing refspecs git_config_set_multivar_gently() will return a non-zero result if there was nothing to delete. Unfortunately the calling code treats that as an error and bails out rather than setting up the new branches. Fix this by not treating a return value of CONFIG_NOTHING_SET as an error. Reported-by: Han Jiang <[email protected]> Signed-off-by: Phillip Wood <[email protected]>
1 parent 4590f2e commit d95a07a

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

builtin/remote.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -1567,8 +1567,12 @@ static int update(int argc, const char **argv, const char *prefix)
15671567

15681568
static int remove_all_fetch_refspecs(const char *key)
15691569
{
1570-
return git_config_set_multivar_gently(key, NULL, NULL,
1571-
CONFIG_FLAGS_MULTI_REPLACE);
1570+
int res = git_config_set_multivar_gently(key, NULL, NULL,
1571+
CONFIG_FLAGS_MULTI_REPLACE);
1572+
if (res == CONFIG_NOTHING_SET)
1573+
res = 0;
1574+
1575+
return res;
15721576
}
15731577

15741578
static void add_branches(struct remote *remote, const char **branches,

t/t5505-remote.sh

+11-3
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,9 @@ test_expect_success 'remote set-branches' '
11311131
+refs/heads/next:refs/remotes/scratch/next
11321132
+refs/heads/seen:refs/remotes/scratch/seen
11331133
EOF
1134-
1134+
cat <<-\EOF >expect.replace-missing &&
1135+
+refs/heads/topic:refs/remotes/scratch/topic
1136+
EOF
11351137
git clone .git/ setbranches &&
11361138
(
11371139
cd setbranches &&
@@ -1161,14 +1163,20 @@ test_expect_success 'remote set-branches' '
11611163
11621164
git remote set-branches --add scratch seen &&
11631165
git config --get-all remote.scratch.fetch >config-result &&
1164-
sort <config-result >../actual.respect-ffonly
1166+
sort <config-result >../actual.respect-ffonly &&
1167+
1168+
git config --unset-all remote.scratch.fetch &&
1169+
git remote set-branches scratch topic &&
1170+
git config --get-all remote.scratch.fetch \
1171+
>../actual.replace-missing
11651172
) &&
11661173
test_cmp expect.initial actual.initial &&
11671174
test_cmp expect.add actual.add &&
11681175
test_cmp expect.replace actual.replace &&
11691176
test_cmp expect.add-two actual.add-two &&
11701177
test_cmp expect.setup-ffonly actual.setup-ffonly &&
1171-
test_cmp expect.respect-ffonly actual.respect-ffonly
1178+
test_cmp expect.respect-ffonly actual.respect-ffonly &&
1179+
test_cmp expect.replace-missing actual.replace-missing
11721180
'
11731181

11741182
test_expect_success 'remote set-branches with --mirror' '

0 commit comments

Comments
 (0)