diff options
author | Bryan C. Mills <bcmills@google.com> | 2019-12-19 23:17:55 -0500 |
---|---|---|
committer | Bryan C. Mills <bcmills@google.com> | 2019-12-20 15:34:39 +0000 |
commit | 3f51350c706c8ff663f12867bcfec98aa9fc46bf (patch) | |
tree | 9e9a1ec090979e60383ffc81b64e3293c131bc7a /src/cmd/go/internal/modfetch/codehost/git.go | |
parent | 82575285913b8b3d7257b21fd33b3226e78e5320 (diff) | |
download | go-3f51350c706c8ff663f12867bcfec98aa9fc46bf.tar.gz go-3f51350c706c8ff663f12867bcfec98aa9fc46bf.zip |
cmd/go/internal/modfetch/codehost: replace a dubious call to semver.Max
The documentation for RecentTag indicates that it returns an actual
tag, not a canonicalized prefix+version blob equivalent to a tag,
so the canonicalization due to semver.Max seems like a bug here.
Fortunately, RecentTag is not currently ever actually used as a tag,
so the removal of metadata does not result in a user-facing bug.
Nonetheless, it may be a subtle source of confusion for maintainers
in the future.
Updates #32700
Change-Id: I525423c1c0c7ec7c36c09e53b180034474f74e5a
Reviewed-on: https://go-review.googlesource.com/c/go/+/212202
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/cmd/go/internal/modfetch/codehost/git.go')
-rw-r--r-- | src/cmd/go/internal/modfetch/codehost/git.go | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/cmd/go/internal/modfetch/codehost/git.go b/src/cmd/go/internal/modfetch/codehost/git.go index e329cbc58e..f08df512f0 100644 --- a/src/cmd/go/internal/modfetch/codehost/git.go +++ b/src/cmd/go/internal/modfetch/codehost/git.go @@ -682,8 +682,11 @@ func (r *gitRepo) RecentTag(rev, prefix, major string) (tag string, err error) { semtag := line[len(prefix):] // Consider only tags that are valid and complete (not just major.minor prefixes). - if c := semver.Canonical(semtag); c != "" && strings.HasPrefix(semtag, c) && (major == "" || semver.Major(c) == major) { - highest = semver.Max(highest, semtag) + // NOTE: Do not replace the call to semver.Compare with semver.Max. + // We want to return the actual tag, not a canonicalized version of it, + // and semver.Max currently canonicalizes (see golang.org/issue/32700). + if c := semver.Canonical(semtag); c != "" && strings.HasPrefix(semtag, c) && (major == "" || semver.Major(c) == major) && semver.Compare(semtag, highest) > 0 { + highest = semtag } } |