Skip to content

Commit 509592d

Browse files
author
Bryan C. Mills
committed
cmd/go: explicitly reject 'list -u' and 'list -versions' when '-mod=vendor' is set
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent cec535b commit 509592d

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

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

+11-2
Original file line numberDiff line numberDiff line change
@@ -390,15 +390,24 @@ func runList(cmd *base.Command, args []string) {
390390

391391
modload.InitMod() // Parses go.mod and sets cfg.BuildMod.
392392
if cfg.BuildMod == "vendor" {
393+
const actionDisabledFormat = "go list -m: can't %s using the vendor directory\n\t(Use -mod=mod or -mod=readonly to bypass.)"
394+
395+
if *listVersions {
396+
base.Fatalf(actionDisabledFormat, "determine available versions")
397+
}
398+
if *listU {
399+
base.Fatalf(actionDisabledFormat, "determine available upgrades")
400+
}
401+
393402
for _, arg := range args {
394403
// In vendor mode, the module graph is incomplete: it contains only the
395404
// explicit module dependencies and the modules that supply packages in
396405
// the import graph. Reject queries that imply more information than that.
397406
if arg == "all" {
398-
base.Fatalf("go list -m: can't compute 'all' using the vendor directory\n\t(Use -mod=mod or -mod=readonly to bypass.)")
407+
base.Fatalf(actionDisabledFormat, "compute 'all'")
399408
}
400409
if strings.Contains(arg, "...") {
401-
base.Fatalf("go list -m: can't match module patterns using the vendor directory\n\t(Use -mod=mod or -mod=readonly to bypass.)")
410+
base.Fatalf(actionDisabledFormat, "match module patterns")
402411
}
403412
}
404413
}

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

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ stdout 'src[\\/]vendor[\\/]x'
3838
go list -mod=vendor -f '{{.Version}} {{.Dir}}' -m x
3939
stdout '^v1.0.0 $'
4040

41+
# -mod=vendor should cause 'go list' flags that look up versions to fail.
42+
! go list -mod=vendor -versions -m x
43+
stderr '^go list -m: can''t determine available versions using the vendor directory\n\t\(Use -mod=mod or -mod=readonly to bypass.\)$'
44+
! go list -mod=vendor -u -m x
45+
stderr '^go list -m: can''t determine available upgrades using the vendor directory\n\t\(Use -mod=mod or -mod=readonly to bypass.\)$'
46+
4147
# 'go list -mod=vendor -m' on a transitive dependency that does not
4248
# provide vendored packages should give a helpful error rather than
4349
# 'not a known dependency'.

0 commit comments

Comments
 (0)