]> git.ipfire.org Git - thirdparty/git.git/commit
fetch: do not ask for HEAD unnecessarily
authorJunio C Hamano <gitster@pobox.com>
Fri, 6 Dec 2024 08:08:00 +0000 (17:08 +0900)
committerJunio C Hamano <gitster@pobox.com>
Sat, 7 Dec 2024 12:58:59 +0000 (21:58 +0900)
commit6c915c3f85f70b6adbe1a6b17dea743e8ff6dee1
treed786dece293662e058ed147e9ad838bf37fd7a7d
parente02082c7f8a29d189334fc23ce829844f63f4ad9
fetch: do not ask for HEAD unnecessarily

In 3f763ddf28 (fetch: set remote/HEAD if it does not exist,
2024-11-22), git-fetch learned to opportunistically set $REMOTE/HEAD
when fetching by always asking for remote HEAD, in the hope that it
will help setting refs/remotes/<name>/HEAD if missing.

But it is not needed to always ask for remote HEAD.  When we are
fetching from a remote, for which we have remote-tracking branches,
we do need to know about HEAD.  But if we are doing one-shot fetch,
e.g.,

  $ git fetch --tags https://github.com/git/git

we do not even know what sub-hierarchy of refs/remotes/<remote>/
we need to adjust the remote HEAD for.  There is no need to ask for
HEAD in such a case.

Incidentally, because the unconditional request to list "HEAD"
affected the number of ref-prefixes requested in the ls-remote
request, this affected how the requests for tags are added to the
same ls-remote request, breaking "git fetch --tags $URL" performed
against a URL that is not configured as a remote.

Reported-by: Josh Steadmon <steadmon@google.com>
[jc: tests are also borrowed from Josh's patch]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fetch.c
t/t5510-fetch.sh