Skip to content

Commit 148bc7b

Browse files
blanetgitster
authored andcommitted
fetch: respect --server-option when fetching multiple remotes
Fix an issue where server options specified via the command line (`--server-option` or `-o`) were not sent when fetching from multiple remotes using Git protocol v2. To reproduce the issue with a repository containing multiple remotes: GIT_TRACE_PACKET=1 git -c protocol.version=2 fetch --server-option=demo --all Observe that no server options are sent to any remote. The root cause was identified in `builtin/fetch.c:fetch_multiple`, which is invoked when fetching from more than one remote. This function forks a `git-fetch` subprocess for each remote but did not include the specified server options in the subprocess arguments. This commit ensures that command-line specified server options are properly passed to each subprocess. Relevant tests have been added. Signed-off-by: Xing Xin <[email protected]> Reviewed-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 094f78a commit 148bc7b

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

builtin/fetch.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,6 +1981,8 @@ static int fetch_multiple(struct string_list *list, int max_children,
19811981
strvec_pushl(&argv, "-c", "fetch.bundleURI=",
19821982
"fetch", "--append", "--no-auto-gc",
19831983
"--no-write-commit-graph", NULL);
1984+
for (i = 0; i < server_options.nr; i++)
1985+
strvec_pushf(&argv, "--server-option=%s", server_options.items[i].string);
19841986
add_options_to_argv(&argv, config);
19851987

19861988
if (max_children != 1 && list->nr != 1) {

t/t5702-protocol-v2.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,16 @@ test_expect_success 'server-options are sent when fetching' '
418418
grep "server-option=world" log
419419
'
420420

421+
test_expect_success 'server-options are sent when fetch multiple remotes' '
422+
test_when_finished "rm -f log server_options_sent" &&
423+
git clone "file://$(pwd)/file_parent" child_multi_remotes &&
424+
git -C child_multi_remotes remote add another "file://$(pwd)/file_parent" &&
425+
GIT_TRACE_PACKET="$(pwd)/log" git -C child_multi_remotes -c protocol.version=2 \
426+
fetch -o hello --all &&
427+
grep "fetch> server-option=hello" log >server_options_sent &&
428+
test_line_count = 2 server_options_sent
429+
'
430+
421431
test_expect_success 'server-options from configuration are used by git-fetch' '
422432
test_when_finished "rm -rf log myclone" &&
423433
git clone "file://$(pwd)/file_parent" myclone &&

0 commit comments

Comments
 (0)