]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modload: make it clear -mod can't be set in some cases
authorMichael Matloob <matloob@golang.org>
Tue, 23 May 2023 20:13:13 +0000 (16:13 -0400)
committerMichael Matloob <matloob@golang.org>
Mon, 4 Mar 2024 21:01:23 +0000 (21:01 +0000)
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>

src/cmd/go/internal/modload/init.go

index f4f4a68254b1663a3b3743eac90ecbb3bad16a6f..23db438da1919a06a8291b216f7fcc86e66c09b9 100644 (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