aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/list.go
diff options
context:
space:
mode:
authorJay Conrod <jayconrod@google.com>2019-05-31 18:56:28 -0400
committerJay Conrod <jayconrod@google.com>2019-06-14 18:01:34 +0000
commit4c2ffd26ec3fe2fb9552b5a38c2b731e86a85abf (patch)
tree717c4be2f345ecd5614499e284afe758cdf900ce /src/cmd/go/internal/modload/list.go
parent80f89133ea54b96d491f8780daaac253ed09abe9 (diff)
downloadgo-4c2ffd26ec3fe2fb9552b5a38c2b731e86a85abf.tar.gz
go-4c2ffd26ec3fe2fb9552b5a38c2b731e86a85abf.zip
cmd/go: avoid accidental downgrades in 'go get' with latest and patch
Currently, 'go get -u' and 'go get -u=patch' avoid accidentally downgrading modules by preventing upgrades in two cases: 1) If the current version is a prerelease that is semantically later than the "latest" or "patch" version. 2) If the current version is a pseudoversion that is chronologically newer than the "latest" or "patch" version. With this change, 'go get m@latest' and 'go get m@patch' prevent downgrades using the same checks. Also: 'go get m@patch' now works if m is a module path but not a package path (i.e., there is no package in the module root directory). Fixes #30634 Fixes #32537 Change-Id: I916630c385b5f3ba7c13e0d65ba08f73a1a67829 Reviewed-on: https://go-review.googlesource.com/c/go/+/180337 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/internal/modload/list.go')
-rw-r--r--src/cmd/go/internal/modload/list.go20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/cmd/go/internal/modload/list.go b/src/cmd/go/internal/modload/list.go
index 5d5c3288b8..c571ddc5f5 100644
--- a/src/cmd/go/internal/modload/list.go
+++ b/src/cmd/go/internal/modload/list.go
@@ -55,18 +55,28 @@ func listModules(args []string, listVersions bool) []*modinfo.ModulePublic {
base.Fatalf("go: cannot use relative path %s to specify module", arg)
}
if i := strings.Index(arg, "@"); i >= 0 {
- info, err := Query(arg[:i], arg[i+1:], nil)
+ path := arg[:i]
+ vers := arg[i+1:]
+ var current string
+ for _, m := range buildList {
+ if m.Path == path {
+ current = m.Version
+ break
+ }
+ }
+
+ info, err := Query(path, vers, current, nil)
if err != nil {
mods = append(mods, &modinfo.ModulePublic{
- Path: arg[:i],
- Version: arg[i+1:],
+ Path: path,
+ Version: vers,
Error: &modinfo.ModuleError{
Err: err.Error(),
},
})
continue
}
- mods = append(mods, moduleInfo(module.Version{Path: arg[:i], Version: info.Version}, false))
+ mods = append(mods, moduleInfo(module.Version{Path: path, Version: info.Version}, false))
continue
}
@@ -101,7 +111,7 @@ func listModules(args []string, listVersions bool) []*modinfo.ModulePublic {
// Don't make the user provide an explicit '@latest' when they're
// explicitly asking what the available versions are.
// Instead, resolve the module, even if it isn't an existing dependency.
- info, err := Query(arg, "latest", nil)
+ info, err := Query(arg, "latest", "", nil)
if err == nil {
mods = append(mods, moduleInfo(module.Version{Path: arg, Version: info.Version}, false))
} else {