]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: explicitly reject 'list -u' and 'list -versions' when '-mod=vendor' is set
authorBryan C. Mills <bcmills@google.com>
Thu, 9 Jan 2020 16:19:16 +0000 (11:19 -0500)
committerBryan C. Mills <bcmills@google.com>
Thu, 9 Jan 2020 17:52:45 +0000 (17:52 +0000)
The information requested by these flags is not available from the
vendor directory.

Noticed while diagnosing #36478.

Updates #33848

Change-Id: I2b181ba5c27f01fdd6277d8d0ab1003c05774ff7
Reviewed-on: https://go-review.googlesource.com/c/go/+/214081
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
src/cmd/go/internal/list/list.go
src/cmd/go/testdata/script/mod_vendor.txt

index 450228964639c6493da8667c5ebd458f0ee7ef94..8d979e276f1cde3271e395bc87af33c3c1d7502d 100644 (file)
@@ -390,15 +390,24 @@ func runList(cmd *base.Command, args []string) {
 
                modload.InitMod() // Parses go.mod and sets cfg.BuildMod.
                if cfg.BuildMod == "vendor" {
+                       const actionDisabledFormat = "go list -m: can't %s using the vendor directory\n\t(Use -mod=mod or -mod=readonly to bypass.)"
+
+                       if *listVersions {
+                               base.Fatalf(actionDisabledFormat, "determine available versions")
+                       }
+                       if *listU {
+                               base.Fatalf(actionDisabledFormat, "determine available upgrades")
+                       }
+
                        for _, arg := range args {
                                // In vendor mode, the module graph is incomplete: it contains only the
                                // explicit module dependencies and the modules that supply packages in
                                // the import graph. Reject queries that imply more information than that.
                                if arg == "all" {
-                                       base.Fatalf("go list -m: can't compute 'all' using the vendor directory\n\t(Use -mod=mod or -mod=readonly to bypass.)")
+                                       base.Fatalf(actionDisabledFormat, "compute 'all'")
                                }
                                if strings.Contains(arg, "...") {
-                                       base.Fatalf("go list -m: can't match module patterns using the vendor directory\n\t(Use -mod=mod or -mod=readonly to bypass.)")
+                                       base.Fatalf(actionDisabledFormat, "match module patterns")
                                }
                        }
                }
index bb3e634b3a35dc96c26d34249747205043727b1c..2622916f614140cf09b49cb4afba4a9655e22609 100644 (file)
@@ -38,6 +38,12 @@ stdout 'src[\\/]vendor[\\/]x'
 go list -mod=vendor -f '{{.Version}} {{.Dir}}' -m x
 stdout '^v1.0.0 $'
 
+# -mod=vendor should cause 'go list' flags that look up versions to fail.
+! go list -mod=vendor -versions -m x
+stderr '^go list -m: can''t determine available versions using the vendor directory\n\t\(Use -mod=mod or -mod=readonly to bypass.\)$'
+! go list -mod=vendor -u -m x
+stderr '^go list -m: can''t determine available upgrades using the vendor directory\n\t\(Use -mod=mod or -mod=readonly to bypass.\)$'
+
 # 'go list -mod=vendor -m' on a transitive dependency that does not
 # provide vendored packages should give a helpful error rather than
 # 'not a known dependency'.