-
Notifications
You must be signed in to change notification settings - Fork 17.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/go: avoid upgrading to +incompatible versions if the latest compa…
…tible one has a go.mod file Previously we would always “upgrade” to the semantically-highest version, even if a newer compatible version exists. That made certain classes of mistakes irreversible: in general we expect users to address bad releases by releasing a new (higher) version, but if the bad release was an unintended +incompatible version, then no release that includes a go.mod file can ever have a higher version, and the bad release will be treated as “latest” forever. Instead, when considering a +incompatible version we now consult the latest compatible (v0 or v1) release first. If the compatible release contains a go.mod file, we ignore the +incompatible releases unless they are expicitly requested (by version, commit ID, or branch name). Fixes #34165 Updates #34189 Change-Id: I7301eb963bbb91b21d3b96a577644221ed988ab7 Reviewed-on: https://go-review.googlesource.com/c/go/+/204440 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
- Loading branch information
Bryan C. Mills
committed
Nov 6, 2019
1 parent
649f341
commit de70de6
Showing
4 changed files
with
189 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Regression test for golang.org/issue/34189 and golang.org/issue/34165: | ||
# @latest, @upgrade, and @patch should prefer compatible versions over | ||
# +incompatible ones, even if offered by a proxy. | ||
|
||
[!net] skip | ||
|
||
env GO111MODULE=on | ||
env GOPROXY= | ||
env GOSUMDB= | ||
|
||
# github.com/russross/blackfriday v2.0.0+incompatible exists, | ||
# and should be resolved if we ask for v2.0 explicitly. | ||
|
||
go list -m github.com/russross/blackfriday@v2.0 | ||
stdout '^github.com/russross/blackfriday v2\.0\.0\+incompatible$' | ||
|
||
# blackfriday v1.5.2 has a go.mod file, so v1.5.2 should be preferred over | ||
# v2.0.0+incompatible when resolving latest, upgrade, and patch. | ||
|
||
go list -m github.com/russross/blackfriday@latest | ||
stdout '^github.com/russross/blackfriday v1\.' | ||
|
||
go list -m github.com/russross/blackfriday@upgrade | ||
stdout '^github.com/russross/blackfriday v1\.' | ||
|
||
go list -m github.com/russross/blackfriday@patch | ||
stdout '^github.com/russross/blackfriday v1\.' | ||
|
||
# If we're fetching directly from version control, ignored +incompatible | ||
# versions should also be omitted by 'go list'. | ||
|
||
# (Note that they may still be included in results from a proxy: in proxy mode, | ||
# we would need to fetch the whole zipfile for the latest compatible version in | ||
# order to determine whether it contains a go.mod file, and part of the point of | ||
# the proxy is to avoid fetching unnecessary data.) | ||
|
||
env GOPROXY=direct | ||
|
||
go list -versions -m github.com/russross/blackfriday github.com/russross/blackfriday | ||
stdout '^github.com/russross/blackfriday v1\.5\.1 v1\.5\.2' # and possibly others | ||
! stdout ' v2\.' | ||
|
||
# However, if the latest compatible version does not include a go.mod file, | ||
# +incompatible versions should still be listed, as they may still reflect the | ||
# intent of the module author. | ||
|
||
go list -versions -m github.com/rsc/legacytest | ||
stdout '^github.com/rsc/legacytest v1\.0\.0 v1\.1\.0-pre v1\.2\.0 v2\.0\.0\+incompatible' | ||
|
||
# If we're fetching directly from version control, asking for a commit hash | ||
# corresponding to a +incompatible version should continue to produce the | ||
# +incompatible version tagged for that commit, even if it is no longer listed. | ||
|
||
go list -m github.com/russross/blackfriday@cadec560ec52 | ||
stdout '^github.com/russross/blackfriday v2\.0\.0\+incompatible$' | ||
|
||
# Similarly, requesting an untagged commit should continue to produce a +incompatible | ||
# pseudo-version. | ||
|
||
go list -m github.com/rsc/legacytest@7303f7796364 | ||
stdout '^github.com/rsc/legacytest v2\.0\.1-0\.20180717164253-7303f7796364\+incompatible$' | ||
|
||
-- go.mod -- | ||
module github.com/golang.org/issue/34165 |