]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix error messages for go mod download in GOPATH mode
authorConstantin Konstantinidis <constantinkonstantinidis@gmail.com>
Sat, 1 Jun 2019 16:14:04 +0000 (18:14 +0200)
committerJay Conrod <jayconrod@google.com>
Fri, 7 Jun 2019 17:03:03 +0000 (17:03 +0000)
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>
src/cmd/go/internal/modcmd/download.go
src/cmd/go/testdata/script/mod_off.txt

index 9f8c410b82f78b9e3619cd597922609b7682e4f8..71b660d6fde326e7f468794db4a5f1c8673fff43 100644 (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"}
        }
index bc0a7861f4b6ca7f3f7819112610a997323b43c0..cada6deb1dd871182c255821aebd7d723d695c10 100644 (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