aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/init.go
diff options
context:
space:
mode:
authorJay Conrod <jayconrod@google.com>2020-09-29 16:40:57 -0400
committerJay Conrod <jayconrod@google.com>2020-09-30 13:18:19 +0000
commit8b0d00b1645c47076f5b20dc692b2ca6d9bac19b (patch)
treee5ce0b5537c5db8e67608ac322a7a0e8b95bbd04 /src/cmd/go/internal/modload/init.go
parent3caaaddffd605c0ec1787d68295b732fff73026b (diff)
downloadgo-8b0d00b1645c47076f5b20dc692b2ca6d9bac19b.tar.gz
go-8b0d00b1645c47076f5b20dc692b2ca6d9bac19b.zip
cmd/go: error if -modfile used with 'go install pkg@version'
'go install pkg@version' runs without a main module or a module root directory. The -modfile flag cannot be used to set the module root directory or to substitute a different go.mod file. This error won't be reported if -modfile is set in GOFLAGS. Unsupported flags there are generally ignored. For #40276 Change-Id: I0b39b1fa9184c15c6e863b647d43c328710920f4 Reviewed-on: https://go-review.googlesource.com/c/go/+/258297 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'src/cmd/go/internal/modload/init.go')
-rw-r--r--src/cmd/go/internal/modload/init.go5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go
index 9d05eadda5..3344242489 100644
--- a/src/cmd/go/internal/modload/init.go
+++ b/src/cmd/go/internal/modload/init.go
@@ -163,8 +163,9 @@ func Init() {
// Running 'go mod init': go.mod will be created in current directory.
modRoot = base.Cwd
} else if RootMode == NoRoot {
- // TODO(jayconrod): report an error if -mod -modfile is explicitly set on
- // the command line. Ignore those flags if they come from GOFLAGS.
+ if cfg.ModFile != "" && !base.InGOFLAGS("-modfile") {
+ base.Fatalf("go: -modfile cannot be used with commands that ignore the current module")
+ }
modRoot = ""
} else {
modRoot = findModuleRoot(base.Cwd)