mirror of
https://github.com/golang/go
synced 2024-09-29 22:14:29 -06:00
cmd/go/internal/modload: make 'list -u' consider current pseudoversion
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>
This commit is contained in:
parent
e4c0e9df8b
commit
f03b3331c7
@ -12,6 +12,7 @@ import (
|
||||
"cmd/go/internal/modinfo"
|
||||
"cmd/go/internal/module"
|
||||
"cmd/go/internal/search"
|
||||
"cmd/go/internal/semver"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"internal/goroot"
|
||||
@ -74,15 +75,17 @@ func ModuleInfo(path string) *modinfo.ModulePublic {
|
||||
|
||||
// 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 {
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// addVersions fills in m.Versions with the list of known versions.
|
||||
|
13
src/cmd/go/testdata/mod/example.com_pseudoupgrade_v0.0.0-20190429073000-30950c05d534.txt
vendored
Normal file
13
src/cmd/go/testdata/mod/example.com_pseudoupgrade_v0.0.0-20190429073000-30950c05d534.txt
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
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
|
13
src/cmd/go/testdata/mod/example.com_pseudoupgrade_v0.1.0.txt
vendored
Normal file
13
src/cmd/go/testdata/mod/example.com_pseudoupgrade_v0.1.0.txt
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
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
|
13
src/cmd/go/testdata/mod/example.com_pseudoupgrade_v0.1.1-0.20190429073117-b5426c86b553.txt
vendored
Normal file
13
src/cmd/go/testdata/mod/example.com_pseudoupgrade_v0.1.1-0.20190429073117-b5426c86b553.txt
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
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
|
30
src/cmd/go/testdata/script/mod_get_upgrade_pseudo.txt
vendored
Normal file
30
src/cmd/go/testdata/script/mod_get_upgrade_pseudo.txt
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
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"
|
24
src/cmd/go/testdata/script/mod_list_upgrade_pseudo.txt
vendored
Normal file
24
src/cmd/go/testdata/script/mod_list_upgrade_pseudo.txt
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
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
|
Loading…
Reference in New Issue
Block a user