1
0
mirror of https://github.com/golang/go synced 2024-11-22 16:04:40 -07:00

[dev.cmdgo] cmd/go: allow expliticly setting -mod=readonly in workspace mode

Change-Id: Iedbe47d087d17984a9d839c13c4b7e6c1fa0deaa
Reviewed-on: https://go-review.googlesource.com/c/go/+/338594
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
Michael Matloob 2021-07-30 14:10:25 -04:00
parent 8e2ab05dd3
commit 90830699ae
2 changed files with 7 additions and 6 deletions

View File

@ -947,8 +947,8 @@ func requirementsFromModFiles(ctx context.Context, modFiles []*modfile.File) *Re
// wasn't provided. setDefaultBuildMod may be called multiple times.
func setDefaultBuildMod() {
if cfg.BuildModExplicit {
if inWorkspaceMode() {
base.Fatalf("go: -mod can't be set explicitly when in workspace mode." +
if inWorkspaceMode() && cfg.BuildMod != "readonly" {
base.Fatalf("go: -mod may only be set to readonly when in workspace mode." +
"\n\tRemove the -mod flag to use the default readonly value," +
"\n\tor set -workfile=off to disable workspace mode.")
}

View File

@ -21,10 +21,11 @@ go list all # all includes both modules
stdout 'example.com/a'
stdout 'example.com/b'
# -mod can't be set in workspace mode, even to readonly
! go list -mod=readonly all
stderr '^go: -mod can''t be set explicitly'
go list -mod=readonly -workfile=off all
# -mod can only be set to readonly in workspace mode
go list -mod=readonly all
! go list -mod=mod all
stderr '^go: -mod may only be set to readonly when in workspace mode'
go list -mod=mod -workfile=off all
# Test that duplicates in the directory list return an error
cp go.work go.work.backup