git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Tags are no longer fetched when fetching specific commit

From
Taylor Blau <me@ttaylorr.com>
Date
Feb 13, 2025, 22:38 UTC
Message-ID
<Z650WoqFwCSo6svH@nand.local>
In-Reply-To
<71075837-D0AA-4F01-9F5D-CA10BFE93B63@ca.ibm.com>
On Thu, Jan 30, 2025 at 03:49:20AM +0000, Igor Todorovski wrote:
Show 36 quoted lines
> Hi, we have noticed a change in behaviour with commit 3f763ddf28d28fe63963991513c8db4045eabadc.
>
> Here’s the steps to reproduce:
>
> mkdir git-test-dir
> cd git-test-dir
> git init --bare
> git remote add origin -- https://github.com/golang/go
> git -c protocol.version=2 fetch -f --depth=1 origin 16afa6a740fac7442e94dcd2ec5ea4a4853e45dc:refs/dummy
> git -c log.showsignature=false log --no-decorate -n1 --format="format:%H %ct %D" 16afa6a740fac7442e94dcd2ec5ea4a4853e45dc --
>
> # Expected:
> # 16afa6a740fac7442e94dcd2ec5ea4a4853e45dc 1734108730 grafted, tag: go1.24rc1, refs/dummy
>
> # Tags are not fetch when using 2.48.1:
> # 16afa6a740fac7442e94dcd2ec5ea4a4853e45dc 1734108730 grafted
>
> ---
>
> git bisect revealed 3f763ddf28d28fe63963991513c8db4045eabadc as the culprit:
>
> commit 3f763ddf28d28fe63963991513c8db4045eabadc
> Author: Bence Ferdinandy
> Date:   Fri Nov 22 13:28:50 2024 +0100
>
>     fetch: set remote/HEAD if it does not exist
>
>     When cloning a repository remote/HEAD is created, but when the user
>     creates a repository with git init, and later adds a remote, remote/HEAD
>     is only created if the user explicitly runs a variant of "remote
>     set-head". Attempt to set remote/HEAD during fetch, if the user does not
>     have it already set. Silently ignore any errors.
>
>     Signed-off-by: Bence Ferdinandy bence@ferdinandy.com
>     Signed-off-by: Junio C Hamano gitster@pobox.com
>

Thanks for the report and bisection recipe. I was able to bisect the same issue myself, and also found myself at 3f763ddf28 (fetch: set remote/HEAD if it does not exist, 2024-11-22).

> Is this intended?

I don't think this was intentional, though the commit's author Bence (CC'd) can confirm.

I suspect what's going on here is that in 3f763ddf28 and onwards we are explicitly adding "HEAD" to the list of ref_prefixes, which causes the server to respond only to the prefixes being asked for. In a pre-3f763ddf28 world, the ref_prefixes list would be empty (if invoked according to your script above), which allowed us to learn about any tags pointing at that commit.

One way to fix it is to move adding the "HEAD" prefix to above where we check

    if (tags == TAGS_SET || tags == TAGS_DEFAULT)

, which would allow us to enter the inner-most conditional which guards us actually adding the refs/tags prefix to our list.

But I don't love that solution, and I think even that is incomplete since as of 6c915c3f85 (fetch: do not ask for HEAD unnecessarily, 2024-12-06) we only ask for "HEAD" if we have a remote in the first place.

I think the real culprit is that we can no longer hold the same assumption from e70a3030e7 (fetch: do not list refs if fetching only hashes, 2018-09-27), which is that we can avoid asking for refs/tags as an explicit prefix if we're (a) fetching literal hashes, (b) tag following wasn't requested, and (c) the fetch is done with protocol v2.

So I think the right fix would really be something like:
--- 8< ---
diff --git a/builtin/fetch.c b/builtin/fetch.c
index fe2b26c74a..0e63621e6c 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -1770,9 +1770,8 @@ static int do_fetch(struct transport *transport,

 	if (tags == TAGS_SET || tags == TAGS_DEFAULT) {
 		must_list_refs = 1;
-		if (transport_ls_refs_options.ref_prefixes.nr)
-			strvec_push(&transport_ls_refs_options.ref_prefixes,
-				    "refs/tags/");
+		strvec_push(&transport_ls_refs_options.ref_prefixes,
+			    "refs/tags/");
 	}

 	if (uses_remote_tracking(transport, rs)) {
--- >8 ---

But I'm unfamiliar enough with this area that I'd appreciate comments
from the authors of these various commits, all of whom have been CC'd.
Does this seem right to you, or am I totally down the wrong path?

Thanks,
Taylor
Previous: Igor TodorovskiNext: Bence Ferdinandy
Message 2 of 61 in “Tags are no longer fetched when fetching specific commit”
  1. Igor TodorovskiJan 30, 2025
  2. Taylor BlauFeb 13, 2025
  3. Bence FerdinandyFeb 14, 2025
  4. Junio C HamanoFeb 14, 2025
  5. Jeff KingFeb 21, 2025
  6. fetch: fix following tags when fetching specific OIDTaylor Blau, Mar 7, 2025
  7. Taylor BlauMar 7, 2025
  8. Junio C HamanoMar 8, 2025
  9. Bence FerdinandyMar 8, 2025
  10. 0/9 fetch: further ref-prefix cleanups and optimizationsJeff King, Mar 9, 2025
  11. 1/9 t5702: fix typo in test nameJeff King, Mar 9, 2025
  12. Taylor BlauMar 12, 2025
  13. Jeff KingMar 13, 2025
  14. 2/9 t5516: prefer "oid" to "sha1" in some test titlesJeff King, Mar 9, 2025
  15. 3/9 t5516: drop NEEDSWORK about v2 reachability behaviorJeff King, Mar 9, 2025
  16. Taylor BlauMar 12, 2025
  17. 4/9 t5516: beef up exact-oid ref prefixes testJeff King, Mar 9, 2025
  18. 5/9 refspec_ref_prefixes(): clean up refspec_item logicJeff King, Mar 9, 2025
  19. Taylor BlauMar 12, 2025
  20. Jeff KingMar 13, 2025
  21. Junio C HamanoMar 13, 2025
  22. 0/4 refspec: treat 'fetch' as a Boolean valueTaylor Blau, Mar 17, 2025
  23. 1/4 refspec: treat 'fetch' as a Boolean valueTaylor Blau, Mar 17, 2025
  24. Jeff KingMar 18, 2025
  25. Jeff KingMar 18, 2025
  26. Taylor BlauMar 18, 2025
  27. 2/4 refspec: replace `refspec_init()` with fetch/push variantsTaylor Blau, Mar 17, 2025
  28. 3/4 refspec: remove refspec_item_init_or_die()Taylor Blau, Mar 17, 2025
  29. 4/4 refspec: replace `refspec_item_init()` with fetch/push variantsTaylor Blau, Mar 17, 2025
  30. Junio C HamanoMar 17, 2025
  31. Taylor BlauMar 18, 2025
  32. 0/4 refspec: treat 'fetch' as a Boolean valueTaylor Blau, Mar 18, 2025
  33. 1/4 refspec: treat 'fetch' as a Boolean valueTaylor Blau, Mar 18, 2025
  34. 2/4 refspec: replace `refspec_init()` with fetch/push variantsTaylor Blau, Mar 18, 2025
  35. 3/4 refspec: remove refspec_item_init_or_die()Taylor Blau, Mar 18, 2025
  36. 4/4 refspec: replace `refspec_item_init()` with fetch/push variantsTaylor Blau, Mar 18, 2025
  37. Elijah NewrenMar 19, 2025
  38. Taylor BlauMar 17, 2025
  39. Junio C HamanoMar 17, 2025
  40. Taylor BlauMar 18, 2025
  41. 6/9 fetch: ask server to advertise HEAD for config-less fetchJeff King, Mar 9, 2025
  42. Taylor BlauMar 12, 2025
  43. Jeff KingMar 13, 2025
  44. Junio C HamanoMar 13, 2025
  45. Taylor BlauMar 17, 2025
  46. 7/9 fetch: stop protecting additions to ref-prefix listJeff King, Mar 9, 2025
  47. Taylor BlauMar 12, 2025
  48. 8/9 fetch: avoid ls-refs only to ask for HEAD symref updateJeff King, Mar 9, 2025
  49. Junio C HamanoMar 13, 2025
  50. Jeff KingMar 17, 2025
  51. Junio C HamanoMar 17, 2025
  52. 0/2 limiting followRemoteHEAD being usedJeff King, Mar 18, 2025
  53. 1/2 fetch: only respect followRemoteHEAD with configured refspecsJeff King, Mar 18, 2025
  54. Taylor BlauMar 18, 2025
  55. 2/2 fetch: don't ask for remote HEAD if followRemoteHEAD is "never"Jeff King, Mar 18, 2025
  56. Junio C HamanoMar 18, 2025
  57. Taylor BlauMar 18, 2025
  58. 9/9 fetch: use ref prefix list to skip ls-refsJeff King, Mar 9, 2025
  59. Taylor BlauMar 12, 2025
  60. Taylor BlauMar 12, 2025
  61. Jeff KingMar 13, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.