Skip to content

Commit cec535b

Browse files
author
Bryan C. Mills
committed
cmd/go/internal/modload: do not disable Query for -mod=readonly
'go list -m' allows explicit module@version arguments, which it resolves (using Query) but does not add to the build list. Similarly, 'go list -u' resolves versions without modifying the build list. These explicit operations should be allowed even when '-mod=readonly' is set. Updates #36478 'go list' and 'go mod download' do not Change-Id: I5d2735729ad573635b9c1902d5d3a8bd960b8a76 Reviewed-on: https://go-review.googlesource.com/c/go/+/214077 Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent 957259b commit cec535b

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/cmd/go/internal/modload/query.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func queryProxy(proxy, path, query, current string, allowed func(module.Version)
7979
if current != "" && !semver.IsValid(current) {
8080
return nil, fmt.Errorf("invalid previous version %q", current)
8181
}
82-
if cfg.BuildMod != "" && cfg.BuildMod != "mod" {
82+
if cfg.BuildMod == "vendor" {
8383
return nil, errQueryDisabled
8484
}
8585
if allowed == nil {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ go list all
3434
go clean -modcache
3535
go list all
3636

37+
# -mod=readonly must not cause 'go list -m' to fail.
38+
# (golang.org/issue/36478)
39+
go list -m all
40+
! stderr 'cannot query module'
41+
3742
# -mod=readonly should reject inconsistent go.mod files
3843
# (ones that would be rewritten).
3944
go mod edit -require rsc.io/[email protected]

0 commit comments

Comments
 (0)