From: Russ Cox Date: Tue, 14 Jan 2025 04:00:14 +0000 (-0500) Subject: [release-branch.go1.23] cmd/go/internal/modfetch: do not trust server to send all... X-Git-Tag: go1.23.6~2 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ab44565bcd9ad975b87ffd78c36c1fae1644d0bf;p=gostls13.git [release-branch.go1.23] 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. For #71261 Fixes #71263 Change-Id: I9fd4f3fd7beeb68a522938599f8f3acd887d0b26 Reviewed-on: https://go-review.googlesource.com/c/go/+/642437 Reviewed-by: Michael Matloob LUCI-TryBot-Result: Go LUCI Auto-Submit: Russ Cox (cherry picked from commit bd80d8956f3062d2b2bff2d7da6b879dfa909f12) Reviewed-on: https://go-review.googlesource.com/c/go/+/642696 Reviewed-by: Michael Knyszek Reviewed-by: Russ Cox --- diff --git a/src/cmd/go/internal/modfetch/codehost/git.go b/src/cmd/go/internal/modfetch/codehost/git.go index bab4c5ebbe..9996be7af7 100644 --- a/src/cmd/go/internal/modfetch/codehost/git.go +++ b/src/cmd/go/internal/modfetch/codehost/git.go @@ -662,7 +662,21 @@ func (r *gitRepo) statLocal(ctx context.Context, version, rev string) (*RevInfo, } } } - sort.Strings(info.Tags) + + // Git 2.47.1 does not send the tags during shallow clone anymore + // (perhaps the exact version that changed behavior is an earlier one), + // so we have to also add tags from the refs list we fetched with ls-remote. + if refs, err := r.loadRefs(ctx); err == nil { + for ref, h := range refs { + if h == hash { + if tag, found := strings.CutPrefix(ref, "refs/tags/"); found { + info.Tags = append(info.Tags, tag) + } + } + } + } + slices.Sort(info.Tags) + info.Tags = slices.Compact(info.Tags) // Used hash as info.Version above. // Use caller's suggested version if it appears in the tag list