if search.IsRelativePath(arg) {
base.Fatalf("go: cannot use relative path %s to specify module", arg)
}
- if !HasModRoot() && (arg == "all" || strings.Contains(arg, "...")) {
- base.Fatalf("go: cannot match %q: %v", arg, ErrNoModRoot)
+ if !HasModRoot() {
+ if arg == "all" || strings.Contains(arg, "...") {
+ base.Fatalf("go: cannot match %q: %v", arg, ErrNoModRoot)
+ }
+ if !listVersions && !strings.Contains(arg, "@") {
+ base.Fatalf("go: cannot match %q without -versions or an explicit version: %v", arg, ErrNoModRoot)
+ }
}
if i := strings.Index(arg, "@"); i >= 0 {
path := arg[:i]
stderr 'go: cannot match "all": go.mod file not found in current directory or any parent directory; see ''go help modules''$'
! stdout 'example.com/version'
+# 'go list -m <mods>' should fail if any of the mods lacks an explicit version.
+! go list -m example.com/printversion
+stderr 'go: cannot match "example.com/printversion" without -versions or an explicit version: go.mod file not found in current directory or any parent directory; see ''go help modules''$'
+! 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 ...