As pointed out by thepudds in #30634, the 'list -u' documentation states that the current version should be considered for upgrade:
The -u flag adds information about available upgrades. When the latest version of a given module is newer than the current one, list -u sets the Module's Update field to information about the newer module.
In go 1.12.4 (and current tip), an older version will be suggested as upgrade to a newer pseudo version.
Updates: #30634
Change-Id: If2c8887198884b8e7ccb3a604908065aa1f1878a
Reviewed-on: https://go-review.googlesource.com/c/go/+/174206
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
"cmd/go/internal/modinfo"
"cmd/go/internal/module"
"cmd/go/internal/search"
+ "cmd/go/internal/semver"
"encoding/hex"
"fmt"
"internal/goroot"
// addUpdate fills in m.Update if an updated version is available.
func addUpdate(m *modinfo.ModulePublic) {
- if m.Version != "" {
- if info, err := Query(m.Path, "latest", Allowed); err == nil && info.Version != m.Version {
- m.Update = &modinfo.ModulePublic{
- Path: m.Path,
- Version: info.Version,
- Time: &info.Time,
- }
+ if m.Version == "" {
+ return
+ }
+
+ if info, err := Query(m.Path, "latest", Allowed); err == nil && semver.Compare(info.Version, m.Version) > 0 {
+ m.Update = &modinfo.ModulePublic{
+ Path: m.Path,
+ Version: info.Version,
+ Time: &info.Time,
}
}
}
--- /dev/null
+example.com/pseudoupgrade v0.0.0-20190429073000-30950c05d534
+written by hand
+
+-- .mod --
+module example.com/pseudoupgrade
+
+-- .info --
+{"Version":"v0.0.0-20190429073000-30950c05d534","Name":"v0.0.0-20190429073000-30950c05d534","Short":"30950c05d534","Time":"2019-04-29T07:30:00Z"}
+
+-- pseudoupgrade.go --
+package pseudoupgrade
+
+const X = 1
--- /dev/null
+example.com/pseudoupgrade v0.1.0
+written by hand
+
+-- .mod --
+module example.com/pseudoupgrade
+
+-- .info --
+{"Version":"v0.1.0","Name":"","Short":"","Time":"2019-04-29T07:30:30Z"}
+
+-- pseudoupgrade.go --
+package pseudoupgrade
+
+const X = 1
--- /dev/null
+example.com/pseudoupgrade v0.1.1-0.20190429073117-b5426c86b553
+written by hand
+
+-- .mod --
+module example.com/pseudoupgrade
+
+-- .info --
+{"Version":"v0.1.1-0.20190429073117-b5426c86b553","Name":"v0.1.1-0.20190429073117-b5426c86b553","Short":"b5426c86b553","Time":"2019-04-29T07:31:00Z"}
+
+-- pseudoupgrade.go --
+package pseudoupgrade
+
+const X = 1
--- /dev/null
+env GO111MODULE=on
+
+# Testing that a pseudo version with schematically higher version than the latest
+# tagged version isn't downgraded when running 'go get -u'.
+
+[!net] skip
+[!exec:git] skip
+
+# For this test repository there are three commits:
+# * b5426c8 "master" (v0.1.1-0.20190429073117-b5426c86b553)
+# * a90cfd2 (tag: v0.1.0)
+# * 30950c0
+
+# When requesting master as specific version, a pseudo version is created with a
+# higher version than the latest tag. Running 'go get -u' doesn't downgrade the
+# version.
+go get -m example.com/pseudoupgrade@b5426c8
+go get -u
+go list -m -u all
+stdout '^example.com/pseudoupgrade v0.1.1-0.20190429073117-b5426c86b553$'
+
+-- go.mod --
+module x
+
+go 1.12
+
+-- main.go --
+package x
+
+import _ "example.com/pseudoupgrade"
--- /dev/null
+env GO111MODULE=on
+
+# Testing that a pseudo version with schematically higher version than the latest
+# tagged version isn't listed as upgradable when calling 'go list -m -u'.
+
+[!net] skip
+[!exec:git] skip
+
+# For this test repository there are three commits:
+# * b5426c8 "master" (v0.1.1-0.20190429073117-b5426c86b553)
+# * a90cfd2 (tag: v0.1.0)
+# * 30950c0
+
+# When requesting master as specific version, a pseudo version is created with a
+# higher version than the latest tag. Listing upgrades doesn't suggest the lower
+# version as upgrade.
+go get -m example.com/pseudoupgrade@b5426c8
+go list -m -u all
+stdout '^example.com/pseudoupgrade v0.1.1-0.20190429073117-b5426c86b553$'
+
+-- go.mod --
+module x
+
+go 1.12