]> git.ipfire.org Git - thirdparty/git.git/commitdiff
promisor-remote: fix promisor.quiet to use the correct repository
authorTrieu Huynh <vikingtc4@gmail.com>
Mon, 6 Apr 2026 18:30:41 +0000 (03:30 +0900)
committerJunio C Hamano <gitster@pobox.com>
Mon, 6 Apr 2026 19:06:29 +0000 (12:06 -0700)
fetch_objects() reads the promisor.quiet configuration from
the_repository instead of the repo parameter it receives.

This means that when git lazy-fetches objects for a non-main
repository, eg. a submodule that is itself a partial clone opened
via repo_submodule_init(). The submodule's own promisor.quiet
setting is ignored and the superproject's setting is used instead.

Fix by replacing the_repository with repo in the repo_config_get_bool()
call. The practical trigger is git grep --recurse-submodules on a
superproject where the submodule is a partial clone.

Add a test where promisor.quiet is set only in a partial-clone
submodule; a lazy fetch triggered by "git grep --recurse-submodules"
must honor that setting.

Signed-off-by: Trieu Huynh <vikingtc4@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
promisor-remote.c
t/t0410-partial-clone.sh

index 96fa215b06a9249b7533c63bd69dd612003b1c9c..225260b05f8d6511aba4c30639e120fd150d6bae 100644 (file)
@@ -46,7 +46,7 @@ static int fetch_objects(struct repository *repo,
                     "fetch", remote_name, "--no-tags",
                     "--no-write-fetch-head", "--recurse-submodules=no",
                     "--filter=blob:none", "--stdin", NULL);
-       if (!repo_config_get_bool(the_repository, "promisor.quiet", &quiet) && quiet)
+       if (!repo_config_get_bool(repo, "promisor.quiet", &quiet) && quiet)
                strvec_push(&child.args, "--quiet");
        if (start_command(&child))
                die(_("promisor-remote: unable to fork off fetch subprocess"));
index 52e19728a3fca03496900e62a73b1088825bf6c0..dff442da2090b5cb9cfc5fc0d3e77c3182bb1573 100755 (executable)
@@ -717,7 +717,29 @@ test_expect_success 'setup for promisor.quiet tests' '
        git -C server rm foo.t &&
        git -C server commit -m remove &&
        git -C server config uploadpack.allowanysha1inwant 1 &&
-       git -C server config uploadpack.allowfilter 1
+       git -C server config uploadpack.allowfilter 1 &&
+
+       # Setup for submodule repo test: superproject whose submodule is a
+       # partial clone, so that promisor.quiet is read via a non-main repo.
+       rm -rf sub-pc-src sub-pc-srv.bare super-src super-work &&
+       git init sub-pc-src &&
+       test_commit -C sub-pc-src initial file.txt "hello" &&
+
+       git clone --bare sub-pc-src sub-pc-srv.bare &&
+       git -C sub-pc-srv.bare config uploadpack.allowfilter 1 &&
+       git -C sub-pc-srv.bare config uploadpack.allowanysha1inwant 1 &&
+
+       git init super-src &&
+       git -C super-src -c protocol.file.allow=always \
+               submodule add "file://$(pwd)/sub-pc-srv.bare" sub &&
+       git -C super-src commit -m "add submodule" &&
+
+       git -c protocol.file.allow=always clone super-src super-work &&
+       git -C super-work -c protocol.file.allow=always \
+               submodule update --init --filter=blob:none sub &&
+
+       # Allow file:// in the submodule so that lazy-fetch subprocesses work.
+       git -C super-work/sub config protocol.file.allow always
 '
 
 test_expect_success TTY 'promisor.quiet=false shows progress messages' '
@@ -752,6 +774,27 @@ test_expect_success TTY 'promisor.quiet=unconfigured shows progress messages' '
        grep "Receiving objects" err
 '
 
+test_expect_success 'promisor.quiet from submodule repo is honored' '
+       rm -f pc-quiet-trace &&
+
+       # Set promisor.quiet only in the submodule, not the superproject.
+       git -C super-work/sub config promisor.quiet true &&
+
+       # Push a new commit+blob to the server; the blob stays missing in the
+       # partial-clone submodule until a lazy fetch is triggered.
+       test_commit -C sub-pc-src updated new-file.txt "world" &&
+       git -C sub-pc-src push "$(pwd)/sub-pc-srv.bare" HEAD:master &&
+       git -C super-work/sub -c protocol.file.allow=always fetch origin &&
+       git -C super-work/sub reset --mixed origin/master &&
+
+       # grep descends into the submodule and triggers a lazy fetch for the
+       # missing blob; verify the fetch subprocess carries --quiet.
+       GIT_TRACE2_EVENT="$(pwd)/pc-quiet-trace" \
+               git -C super-work grep --cached --recurse-submodules "world" \
+               2>/dev/null &&
+       grep negotiationAlgorithm pc-quiet-trace | grep -e --quiet
+'
+
 . "$TEST_DIRECTORY"/lib-httpd.sh
 start_httpd