Skip to content

Commit f03b333

Browse files
leitzlerJay Conrod
authored and
Jay Conrod
committed
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>
1 parent e4c0e9d commit f03b333

6 files changed

+103
-7
lines changed

src/cmd/go/internal/modload/build.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"cmd/go/internal/modinfo"
1313
"cmd/go/internal/module"
1414
"cmd/go/internal/search"
15+
"cmd/go/internal/semver"
1516
"encoding/hex"
1617
"fmt"
1718
"internal/goroot"
@@ -74,13 +75,15 @@ func ModuleInfo(path string) *modinfo.ModulePublic {
7475

7576
// addUpdate fills in m.Update if an updated version is available.
7677
func addUpdate(m *modinfo.ModulePublic) {
77-
if m.Version != "" {
78-
if info, err := Query(m.Path, "latest", Allowed); err == nil && info.Version != m.Version {
79-
m.Update = &modinfo.ModulePublic{
80-
Path: m.Path,
81-
Version: info.Version,
82-
Time: &info.Time,
83-
}
78+
if m.Version == "" {
79+
return
80+
}
81+
82+
if info, err := Query(m.Path, "latest", Allowed); err == nil && semver.Compare(info.Version, m.Version) > 0 {
83+
m.Update = &modinfo.ModulePublic{
84+
Path: m.Path,
85+
Version: info.Version,
86+
Time: &info.Time,
8487
}
8588
}
8689
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
example.com/pseudoupgrade v0.0.0-20190429073000-30950c05d534
2+
written by hand
3+
4+
-- .mod --
5+
module example.com/pseudoupgrade
6+
7+
-- .info --
8+
{"Version":"v0.0.0-20190429073000-30950c05d534","Name":"v0.0.0-20190429073000-30950c05d534","Short":"30950c05d534","Time":"2019-04-29T07:30:00Z"}
9+
10+
-- pseudoupgrade.go --
11+
package pseudoupgrade
12+
13+
const X = 1
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
example.com/pseudoupgrade v0.1.0
2+
written by hand
3+
4+
-- .mod --
5+
module example.com/pseudoupgrade
6+
7+
-- .info --
8+
{"Version":"v0.1.0","Name":"","Short":"","Time":"2019-04-29T07:30:30Z"}
9+
10+
-- pseudoupgrade.go --
11+
package pseudoupgrade
12+
13+
const X = 1
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
example.com/pseudoupgrade v0.1.1-0.20190429073117-b5426c86b553
2+
written by hand
3+
4+
-- .mod --
5+
module example.com/pseudoupgrade
6+
7+
-- .info --
8+
{"Version":"v0.1.1-0.20190429073117-b5426c86b553","Name":"v0.1.1-0.20190429073117-b5426c86b553","Short":"b5426c86b553","Time":"2019-04-29T07:31:00Z"}
9+
10+
-- pseudoupgrade.go --
11+
package pseudoupgrade
12+
13+
const X = 1
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
env GO111MODULE=on
2+
3+
# Testing that a pseudo version with schematically higher version than the latest
4+
# tagged version isn't downgraded when running 'go get -u'.
5+
6+
[!net] skip
7+
[!exec:git] skip
8+
9+
# For this test repository there are three commits:
10+
# * b5426c8 "master" (v0.1.1-0.20190429073117-b5426c86b553)
11+
# * a90cfd2 (tag: v0.1.0)
12+
# * 30950c0
13+
14+
# When requesting master as specific version, a pseudo version is created with a
15+
# higher version than the latest tag. Running 'go get -u' doesn't downgrade the
16+
# version.
17+
go get -m example.com/pseudoupgrade@b5426c8
18+
go get -u
19+
go list -m -u all
20+
stdout '^example.com/pseudoupgrade v0.1.1-0.20190429073117-b5426c86b553$'
21+
22+
-- go.mod --
23+
module x
24+
25+
go 1.12
26+
27+
-- main.go --
28+
package x
29+
30+
import _ "example.com/pseudoupgrade"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
env GO111MODULE=on
2+
3+
# Testing that a pseudo version with schematically higher version than the latest
4+
# tagged version isn't listed as upgradable when calling 'go list -m -u'.
5+
6+
[!net] skip
7+
[!exec:git] skip
8+
9+
# For this test repository there are three commits:
10+
# * b5426c8 "master" (v0.1.1-0.20190429073117-b5426c86b553)
11+
# * a90cfd2 (tag: v0.1.0)
12+
# * 30950c0
13+
14+
# When requesting master as specific version, a pseudo version is created with a
15+
# higher version than the latest tag. Listing upgrades doesn't suggest the lower
16+
# version as upgrade.
17+
go get -m example.com/pseudoupgrade@b5426c8
18+
go list -m -u all
19+
stdout '^example.com/pseudoupgrade v0.1.1-0.20190429073117-b5426c86b553$'
20+
21+
-- go.mod --
22+
module x
23+
24+
go 1.12

0 commit comments

Comments
 (0)