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>
package modcmd
import (
+ "cmd/go/internal/cfg"
"encoding/json"
"os"
}
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"}
}
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
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