]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modload: make 'list -u' consider current pseudoversion
authorPontus Leitzler <leitzler@gmail.com>
Mon, 29 Apr 2019 09:50:53 +0000 (09:50 +0000)
committerJay Conrod <jayconrod@google.com>
Thu, 2 May 2019 14:47:22 +0000 (14:47 +0000)
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>
src/cmd/go/internal/modload/build.go
src/cmd/go/testdata/mod/example.com_pseudoupgrade_v0.0.0-20190429073000-30950c05d534.txt [new file with mode: 0644]
src/cmd/go/testdata/mod/example.com_pseudoupgrade_v0.1.0.txt [new file with mode: 0644]
src/cmd/go/testdata/mod/example.com_pseudoupgrade_v0.1.1-0.20190429073117-b5426c86b553.txt [new file with mode: 0644]
src/cmd/go/testdata/script/mod_get_upgrade_pseudo.txt [new file with mode: 0644]
src/cmd/go/testdata/script/mod_list_upgrade_pseudo.txt [new file with mode: 0644]

index a41b176ccde4566dc23fbae17a90da67ef8842ae..66a0a75d969f4ba9ca3f49edb2357ffd5e5f7052 100644 (file)
@@ -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,13 +75,15 @@ 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 {
-                       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,
                }
        }
 }
diff --git a/src/cmd/go/testdata/mod/example.com_pseudoupgrade_v0.0.0-20190429073000-30950c05d534.txt b/src/cmd/go/testdata/mod/example.com_pseudoupgrade_v0.0.0-20190429073000-30950c05d534.txt
new file mode 100644 (file)
index 0000000..421e643
--- /dev/null
@@ -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
diff --git a/src/cmd/go/testdata/mod/example.com_pseudoupgrade_v0.1.0.txt b/src/cmd/go/testdata/mod/example.com_pseudoupgrade_v0.1.0.txt
new file mode 100644 (file)
index 0000000..7ddb0dc
--- /dev/null
@@ -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
diff --git a/src/cmd/go/testdata/mod/example.com_pseudoupgrade_v0.1.1-0.20190429073117-b5426c86b553.txt b/src/cmd/go/testdata/mod/example.com_pseudoupgrade_v0.1.1-0.20190429073117-b5426c86b553.txt
new file mode 100644 (file)
index 0000000..b3f48bb
--- /dev/null
@@ -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
diff --git a/src/cmd/go/testdata/script/mod_get_upgrade_pseudo.txt b/src/cmd/go/testdata/script/mod_get_upgrade_pseudo.txt
new file mode 100644 (file)
index 0000000..69acea5
--- /dev/null
@@ -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"
diff --git a/src/cmd/go/testdata/script/mod_list_upgrade_pseudo.txt b/src/cmd/go/testdata/script/mod_list_upgrade_pseudo.txt
new file mode 100644 (file)
index 0000000..6935e03
--- /dev/null
@@ -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