1
0
mirror of https://github.com/golang/go synced 2024-09-28 19:34:28 -06:00

cmd/go/internal/modload: make it clear -mod can't be set in some cases

We check that -mod can't be set to mod in workspace mode, but then we
set BuildMod to mod for go work sync below. Make it clear that that's
okay because we can't pass -mod=mod to go work sync (or the other go
mod commands that can run in workspace mode that set mod=mod: go mod
graph, go mod verify, and go mod why).

Change-Id: Idfe6fea6a420211886e4f838e050be4bf7d1b71d
Reviewed-on: https://go-review.googlesource.com/c/go/+/497617
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Michael Matloob 2023-05-23 16:13:13 -04:00
parent b09ac10bad
commit 5dcc04aeac

View File

@ -1343,9 +1343,16 @@ func appendGoAndToolchainRoots(roots []module.Version, goVersion, toolchain stri
func setDefaultBuildMod() {
if cfg.BuildModExplicit {
if inWorkspaceMode() && cfg.BuildMod != "readonly" && cfg.BuildMod != "vendor" {
base.Fatalf("go: -mod may only be set to readonly or vendor when in workspace mode, but it is set to %q"+
"\n\tRemove the -mod flag to use the default readonly value, "+
"\n\tor set GOWORK=off to disable workspace mode.", cfg.BuildMod)
switch cfg.CmdName {
case "work sync", "mod graph", "mod verify", "mod why":
// These commands run with BuildMod set to mod, but they don't take the
// -mod flag, so we should never get here.
panic("in workspace mode and -mod was set explicitly, but command doesn't support setting -mod")
default:
base.Fatalf("go: -mod may only be set to readonly or vendor when in workspace mode, but it is set to %q"+
"\n\tRemove the -mod flag to use the default readonly value, "+
"\n\tor set GOWORK=off to disable workspace mode.", cfg.BuildMod)
}
}
// Don't override an explicit '-mod=' argument.
return