From: Constantin Konstantinidis Date: Sat, 1 Jun 2019 16:14:04 +0000 (+0200) Subject: cmd/go: fix error messages for go mod download in GOPATH mode X-Git-Tag: go1.13beta1~115 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=5587e05eac5274fc08915c8a64d446bfa3e4855b;p=gostls13.git cmd/go: fix error messages for go mod download in GOPATH mode Checks if modules are enabled in GOPATH mode. Error message returned when no version is provided. Relevant tests updated. Test for GO111MODULE=off added. Fixes #27783 Change-Id: I12cdaced5fa38a9c49c0ecfed4c479eb86ed061f Reviewed-on: https://go-review.googlesource.com/c/go/+/179998 Run-TryBot: Jay Conrod TryBot-Result: Gobot Gobot Reviewed-by: Bryan C. Mills --- diff --git a/src/cmd/go/internal/modcmd/download.go b/src/cmd/go/internal/modcmd/download.go index 9f8c410b82..71b660d6fd 100644 --- a/src/cmd/go/internal/modcmd/download.go +++ b/src/cmd/go/internal/modcmd/download.go @@ -5,6 +5,7 @@ package modcmd import ( + "cmd/go/internal/cfg" "encoding/json" "os" @@ -67,6 +68,13 @@ type moduleJSON struct { } func runDownload(cmd *base.Command, args []string) { + // Check whether modules are enabled and whether we're in a module. + if cfg.Getenv("GO111MODULE") == "off" { + base.Fatalf("go: modules disabled by GO111MODULE=off; see 'go help modules'") + } + if !modload.HasModRoot() && len(args) == 0 { + base.Fatalf("go mod download: no modules specified (see 'go help mod download')") + } if len(args) == 0 { args = []string{"all"} } diff --git a/src/cmd/go/testdata/script/mod_off.txt b/src/cmd/go/testdata/script/mod_off.txt index bc0a7861f4..cada6deb1d 100644 --- a/src/cmd/go/testdata/script/mod_off.txt +++ b/src/cmd/go/testdata/script/mod_off.txt @@ -9,6 +9,8 @@ stderr 'go mod init: modules disabled by GO111MODULE=off; see ''go help modules' stderr 'go: modules disabled by GO111MODULE=off; see ''go help modules''' ! go mod verify stderr 'go: modules disabled by GO111MODULE=off; see ''go help modules''' +! go mod download +stderr 'go: modules disabled by GO111MODULE=off; see ''go help modules''' # Same result in an empty directory mkdir z @@ -19,6 +21,8 @@ stderr 'go mod init: modules disabled by GO111MODULE=off; see ''go help modules' stderr 'go: modules disabled by GO111MODULE=off; see ''go help modules''' ! go mod verify stderr 'go: modules disabled by GO111MODULE=off; see ''go help modules''' +! go mod download +stderr 'go: modules disabled by GO111MODULE=off; see ''go help modules''' -- sample.go -- package sample