]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fetch: respect --server-option when fetching multiple remotes
authorXing Xin <xingxin.xx@bytedance.com>
Tue, 8 Oct 2024 03:38:18 +0000 (03:38 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 Oct 2024 17:22:09 +0000 (10:22 -0700)
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 <xingxin.xx@bytedance.com>
Reviewed-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fetch.c
t/t5702-protocol-v2.sh

index 80a64d0d269ed60708d7533977f9ba5c51a4b084..d9027e4dc9245a32a87c47d89f9a29fcfd42534c 100644 (file)
@@ -1981,6 +1981,8 @@ static int fetch_multiple(struct string_list *list, int max_children,
        strvec_pushl(&argv, "-c", "fetch.bundleURI=",
                     "fetch", "--append", "--no-auto-gc",
                     "--no-write-commit-graph", NULL);
+       for (i = 0; i < server_options.nr; i++)
+               strvec_pushf(&argv, "--server-option=%s", server_options.items[i].string);
        add_options_to_argv(&argv, config);
 
        if (max_children != 1 && list->nr != 1) {
index 5cec2061d28bb3e969c43a6eb286e1fd6ede44c1..d3df81e7852d7db2399ddfd7a1e85612f3353087 100755 (executable)
@@ -418,6 +418,16 @@ test_expect_success 'server-options are sent when fetching' '
        grep "server-option=world" log
 '
 
+test_expect_success 'server-options are sent when fetch multiple remotes' '
+       test_when_finished "rm -f log server_options_sent" &&
+       git clone "file://$(pwd)/file_parent" child_multi_remotes &&
+       git -C child_multi_remotes remote add another "file://$(pwd)/file_parent" &&
+       GIT_TRACE_PACKET="$(pwd)/log" git -C child_multi_remotes -c protocol.version=2 \
+               fetch -o hello --all &&
+       grep "fetch> server-option=hello" log >server_options_sent &&
+       test_line_count = 2 server_options_sent
+'
+
 test_expect_success 'server-options from configuration are used by git-fetch' '
        test_when_finished "rm -rf log myclone" &&
        git clone "file://$(pwd)/file_parent" myclone &&