]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fetch: don't ask for remote HEAD if followRemoteHEAD is "never"
authorJeff King <peff@peff.net>
Tue, 18 Mar 2025 05:41:22 +0000 (01:41 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 18 Mar 2025 19:21:26 +0000 (12:21 -0700)
When we are going to consider updating the refs/remotes/*/HEAD symref,
we have to ask the remote side where its HEAD points. But if we know
that the feature is disabled by config, we don't need to bother!

This saves a little bit of work and network communication for the
server. And even a little bit of effort on the client, as our local
set_head() function did a bit of work matching the remote HEAD before
realizing that we're not going to do anything with it.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fetch.c
t/t5510-fetch.sh

index 66f5ae31b6ec3697dd8fd4f23d79a2126d713a5c..3658509740ed6960c823a409db75ed2b23283d0c 100644 (file)
@@ -1643,9 +1643,6 @@ static int set_head(const struct ref *remote_refs, struct remote *remote)
                string_list_append(&heads, strip_refshead(ref->name));
        }
 
-       if (follow_remote_head == FOLLOW_REMOTE_NEVER)
-               goto cleanup;
-
        if (!heads.nr)
                result = 1;
        else if (heads.nr > 1)
@@ -1729,7 +1726,8 @@ static int do_fetch(struct transport *transport,
                if (transport->remote->fetch.nr) {
                        refspec_ref_prefixes(&transport->remote->fetch,
                                             &transport_ls_refs_options.ref_prefixes);
-                       do_set_head = 1;
+                       if (transport->remote->follow_remote_head != FOLLOW_REMOTE_NEVER)
+                               do_set_head = 1;
                }
                if (branch_has_merge_config(branch) &&
                    !strcmp(branch->remote_name, transport->remote->name)) {
index ad23dd11efc71d4c7579c2f730ee5df0b34f0479..5f0eb5684e839d77f058b3106abc467b006ca39e 100755 (executable)
@@ -119,7 +119,10 @@ test_expect_success "fetch test followRemoteHEAD never" '
                cd two &&
                git update-ref --no-deref -d refs/remotes/origin/HEAD &&
                git config set remote.origin.followRemoteHEAD "never" &&
-               git fetch &&
+               GIT_TRACE_PACKET=$PWD/trace.out git fetch &&
+               # Confirm that we do not even ask for HEAD when we are
+               # not going to act on it.
+               test_grep ! "ref-prefix HEAD" trace.out &&
                test_must_fail git rev-parse --verify refs/remotes/origin/HEAD
        )
 '