Skip to content

Commit 2434869

Browse files
author
Jay Conrod
committed
cmd/go: report an error for 'go list -m ...' outside a module
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 <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 37715cc commit 2434869

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/cmd/go/internal/modload/list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ func listModules(args []string, listVersions bool) []*modinfo.ModulePublic {
5757
if search.IsRelativePath(arg) {
5858
base.Fatalf("go: cannot use relative path %s to specify module", arg)
5959
}
60-
if !HasModRoot() && arg == "all" {
61-
base.Fatalf(`go: cannot match "all": working directory is not part of a module`)
60+
if !HasModRoot() && (arg == "all" || strings.Contains(arg, "...")) {
61+
base.Fatalf("go: cannot match %q: working directory is not part of a module", arg)
6262
}
6363
if i := strings.Index(arg, "@"); i >= 0 {
6464
path := arg[:i]

src/cmd/go/testdata/script/mod_outside.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ stderr 'go: cannot match "all": working directory is not part of a module'
5656
stderr 'go: cannot match "all": working directory is not part of a module'
5757
! stdout 'example.com/version'
5858

59+
# 'go list -m' with wildcards should fail. Wildcards match modules in the
60+
# build list, so they aren't meaningful outside a module.
61+
! go list -m ...
62+
stderr 'go: cannot match "...": working directory is not part of a module'
63+
! go list -m rsc.io/quote/...
64+
stderr 'go: cannot match "rsc.io/quote/...": working directory is not part of a module'
65+
5966

6067
# 'go clean' should skip the current directory if it isn't in a module.
6168
go clean -n

0 commit comments

Comments
 (0)