]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modload: do not disable Query for -mod=readonly
authorBryan C. Mills <bcmills@google.com>
Thu, 9 Jan 2020 14:39:48 +0000 (09:39 -0500)
committerBryan C. Mills <bcmills@google.com>
Thu, 9 Jan 2020 17:52:05 +0000 (17:52 +0000)
'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 <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
src/cmd/go/internal/modload/query.go
src/cmd/go/testdata/script/mod_readonly.txt

index 53278b91002043bfd0c5038798996fb9cad99de9..031e45938a5d7bf18f74016222c0a8571fd12591 100644 (file)
@@ -79,7 +79,7 @@ func queryProxy(proxy, path, query, current string, allowed func(module.Version)
        if current != "" && !semver.IsValid(current) {
                return nil, fmt.Errorf("invalid previous version %q", current)
        }
-       if cfg.BuildMod != "" && cfg.BuildMod != "mod" {
+       if cfg.BuildMod == "vendor" {
                return nil, errQueryDisabled
        }
        if allowed == nil {
index 1d1771e9cc04911e90e21bee21a062c872ea7f18..77fc735d5729a5ca86f190159d466050f9455937 100644 (file)
@@ -34,6 +34,11 @@ go list all
 go clean -modcache
 go list all
 
+# -mod=readonly must not cause 'go list -m' to fail.
+# (golang.org/issue/36478)
+go list -m all
+! stderr 'cannot query module'
+
 # -mod=readonly should reject inconsistent go.mod files
 # (ones that would be rewritten).
 go mod edit -require rsc.io/sampler@v1.2.0