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 <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
Constantin Konstantinidis 2019-06-01 18:14:04 +02:00 committed by Jay Conrod
parent b23ff2c8f9
commit 5587e05eac
2 changed files with 12 additions and 0 deletions

View File

@ -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"}
}

View File

@ -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