aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modcmd/init.go
diff options
context:
space:
mode:
authorJay Conrod <jayconrod@google.com>2020-09-11 13:30:43 -0400
committerJay Conrod <jayconrod@google.com>2020-09-15 12:46:25 +0000
commit03875bd9bc112d25a4496f7ff22888f23a26baea (patch)
tree6f9fc4493cb0b775dabd1affa30d6e4209b153c3 /src/cmd/go/internal/modcmd/init.go
parente3063636124d0e5b2d0fad7912a9c6810629f486 (diff)
downloadgo-03875bd9bc112d25a4496f7ff22888f23a26baea.tar.gz
go-03875bd9bc112d25a4496f7ff22888f23a26baea.zip
cmd/go: add modload.NeedRoot mode for commands that need module root
This makes error reporting a bit more consistent for 'go mod' subcommands. Most of these commands only work in module mode when a go.mod file is present. Setting modload.ForceUseModules reports an error when GO111MODULE=off. Setting modload.RootMode to modload.NeedRoot reports an error when no go.mod file is present. Change-Id: I1daa8d2971cb8658e0c804765839d903734a412e Reviewed-on: https://go-review.googlesource.com/c/go/+/254369 Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Michael Matloob <matloob@golang.org>
Diffstat (limited to 'src/cmd/go/internal/modcmd/init.go')
-rw-r--r--src/cmd/go/internal/modcmd/init.go4
1 files changed, 1 insertions, 3 deletions
diff --git a/src/cmd/go/internal/modcmd/init.go b/src/cmd/go/internal/modcmd/init.go
index 21b235653e..7cfc0e6f5b 100644
--- a/src/cmd/go/internal/modcmd/init.go
+++ b/src/cmd/go/internal/modcmd/init.go
@@ -40,9 +40,7 @@ func runInit(ctx context.Context, cmd *base.Command, args []string) {
if len(args) == 1 {
modload.CmdModModule = args[0]
}
- if os.Getenv("GO111MODULE") == "off" {
- base.Fatalf("go mod init: modules disabled by GO111MODULE=off; see 'go help modules'")
- }
+ modload.ForceUseModules = true
modFilePath := modload.ModFilePath()
if _, err := os.Stat(modFilePath); err == nil {
base.Fatalf("go mod init: go.mod already exists")