]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: report an error for 'go list -m ...' outside a module
authorJay Conrod <jayconrod@google.com>
Thu, 21 Nov 2019 17:50:14 +0000 (12:50 -0500)
committerJay Conrod <jayconrod@google.com>
Thu, 21 Nov 2019 19:09:24 +0000 (19:09 +0000)
Previously, we just reported an error for "all". Now we report an
error for any pattern that matches modules in the build list. The
build list can only contain the module "command-line-arguments", so
these patterns are not meaningful.

Fixes #35728

Change-Id: Ibc736491ec9164588f9657c09d1b9683b33cf1de
Reviewed-on: https://go-review.googlesource.com/c/go/+/208222
Run-TryBot: Jay Conrod <jayconrod@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/go/internal/modload/list.go
src/cmd/go/testdata/script/mod_outside.txt

index c4327276bfcc26008d3d94e874b8f14c5c2ce27b..9400793bcb253b3e7547ea7e6773b22f9d3c4bfb 100644 (file)
@@ -57,8 +57,8 @@ func listModules(args []string, listVersions bool) []*modinfo.ModulePublic {
                if search.IsRelativePath(arg) {
                        base.Fatalf("go: cannot use relative path %s to specify module", arg)
                }
-               if !HasModRoot() && arg == "all" {
-                       base.Fatalf(`go: cannot match "all": working directory is not part of a module`)
+               if !HasModRoot() && (arg == "all" || strings.Contains(arg, "...")) {
+                       base.Fatalf("go: cannot match %q: working directory is not part of a module", arg)
                }
                if i := strings.Index(arg, "@"); i >= 0 {
                        path := arg[:i]
index 34570c76c2cd8767f411c35a1fc018a6a728b1a4..03ef576168c92b9ff853515226552b463204929d 100644 (file)
@@ -56,6 +56,13 @@ stderr 'go: cannot match "all": working directory is not part of a module'
 stderr 'go: cannot match "all": working directory is not part of a module'
 ! stdout 'example.com/version'
 
+# 'go list -m' with wildcards should fail. Wildcards match modules in the
+# build list, so they aren't meaningful outside a module.
+! go list -m ...
+stderr 'go: cannot match "...": working directory is not part of a module'
+! go list -m rsc.io/quote/...
+stderr 'go: cannot match "rsc.io/quote/...": working directory is not part of a module'
+
 
 # 'go clean' should skip the current directory if it isn't in a module.
 go clean -n