Skip to content

Commit bd80d89

Browse files
rscgopherbot
authored andcommitted
cmd/go/internal/modfetch: do not trust server to send all tags in shallow fetch
Newer git versions (at least git 2.47.1) do not send all the matching tags for a shallow fetch of a specific hash anymore. The go command assumes that git servers do this. Since that assumption is broken, use the local copy of the remote refs list to augment the tags sent by the server. This makes the cmd/go/internal/modfetch tests pass again with newer git. Fixes golang#71261. Change-Id: I9fd4f3fd7beeb68a522938599f8f3acd887d0b26 Reviewed-on: https://go-review.googlesource.com/c/go/+/642437 Reviewed-by: Michael Matloob <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Russ Cox <[email protected]>
1 parent 4fa61d6 commit bd80d89

File tree

1 file changed

+15
-1
lines changed
  • src/cmd/go/internal/modfetch/codehost

1 file changed

+15
-1
lines changed

src/cmd/go/internal/modfetch/codehost/git.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,21 @@ func (r *gitRepo) statLocal(ctx context.Context, version, rev string) (*RevInfo,
649649
}
650650
}
651651
}
652-
sort.Strings(info.Tags)
652+
653+
// Git 2.47.1 does not send the tags during shallow clone anymore
654+
// (perhaps the exact version that changed behavior is an earlier one),
655+
// so we have to also add tags from the refs list we fetched with ls-remote.
656+
if refs, err := r.loadRefs(ctx); err == nil {
657+
for ref, h := range refs {
658+
if h == hash {
659+
if tag, found := strings.CutPrefix(ref, "refs/tags/"); found {
660+
info.Tags = append(info.Tags, tag)
661+
}
662+
}
663+
}
664+
}
665+
slices.Sort(info.Tags)
666+
info.Tags = slices.Compact(info.Tags)
653667

654668
// Used hash as info.Version above.
655669
// Use caller's suggested version if it appears in the tag list

0 commit comments

Comments
 (0)