aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/query.go
diff options
context:
space:
mode:
authorJay Conrod <jayconrod@google.com>2020-11-16 16:27:19 -0500
committerJay Conrod <jayconrod@google.com>2020-11-17 18:28:55 +0000
commit01df2febf5f00b1dcba1843093ef99b338b23546 (patch)
tree15512ceb6d0e62a352f88a03b1af6b02e8bb2e72 /src/cmd/go/internal/modload/query.go
parent0968d2d599189229145b1000cec55d9df47fbc98 (diff)
downloadgo-01df2febf5f00b1dcba1843093ef99b338b23546.tar.gz
go-01df2febf5f00b1dcba1843093ef99b338b23546.zip
cmd/go: allow querying other versions of the main module
'go mod download' and a few other commands can now query specific versions of the main module. 'go get' still reports an error when attempting to update the main module. Fixes #42524 Change-Id: Ia93ef8f5f34443e938667c48a0db432200108c63 Reviewed-on: https://go-review.googlesource.com/c/go/+/270520 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/internal/modload/query.go')
-rw-r--r--src/cmd/go/internal/modload/query.go28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/cmd/go/internal/modload/query.go b/src/cmd/go/internal/modload/query.go
index d4a1e85041..e35e0fc16e 100644
--- a/src/cmd/go/internal/modload/query.go
+++ b/src/cmd/go/internal/modload/query.go
@@ -109,10 +109,7 @@ func queryProxy(ctx context.Context, proxy, path, query, current string, allowed
allowed = func(context.Context, module.Version) error { return nil }
}
- if path == Target.Path {
- if query != "upgrade" && query != "patch" {
- return nil, &QueryMatchesMainModuleError{Pattern: path, Query: query}
- }
+ if path == Target.Path && (query == "upgrade" || query == "patch") {
if err := allowed(ctx, Target); err != nil {
return nil, fmt.Errorf("internal error: main module version is not allowed: %w", err)
}
@@ -582,6 +579,7 @@ func QueryPattern(ctx context.Context, pattern, query string, current func(strin
}
}
+ var queryMatchesMainModule bool
if HasModRoot() {
m := match(Target, modRoot, true)
if len(m.Pkgs) > 0 {
@@ -605,7 +603,11 @@ func QueryPattern(ctx context.Context, pattern, query string, current func(strin
return nil, nil, err
}
- if query != "upgrade" && query != "patch" && matchPattern(Target.Path) {
+ if matchPattern(Target.Path) {
+ queryMatchesMainModule = true
+ }
+
+ if (query == "upgrade" || query == "patch") && queryMatchesMainModule {
if err := allowed(ctx, Target); err == nil {
modOnly = &QueryResult{
Mod: Target,
@@ -620,14 +622,20 @@ func QueryPattern(ctx context.Context, pattern, query string, current func(strin
candidateModules = modulePrefixesExcludingTarget(base)
)
if len(candidateModules) == 0 {
- if modOnly == nil {
+ if modOnly != nil {
+ return nil, modOnly, nil
+ } else if queryMatchesMainModule {
+ return nil, nil, &QueryMatchesMainModuleError{
+ Pattern: pattern,
+ Query: query,
+ }
+ } else {
return nil, nil, &PackageNotInModuleError{
Mod: Target,
Query: query,
Pattern: pattern,
}
}
- return nil, modOnly, nil
}
err = modfetch.TryProxies(func(proxy string) error {
@@ -675,6 +683,12 @@ func QueryPattern(ctx context.Context, pattern, query string, current func(strin
return err
})
+ if queryMatchesMainModule && len(results) == 0 && modOnly == nil && errors.Is(err, fs.ErrNotExist) {
+ return nil, nil, &QueryMatchesMainModuleError{
+ Pattern: pattern,
+ Query: query,
+ }
+ }
return results[:len(results):len(results)], modOnly, err
}