aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/get/get.go
diff options
context:
space:
mode:
authorAnton Kuklin <anton.a.kuklin@gmail.com>2020-04-25 02:33:30 +0300
committerJay Conrod <jayconrod@google.com>2020-04-30 22:06:07 +0000
commit4c78d54fdd9ffc81c15ffc3c4a2946f89d4fca22 (patch)
treeede3514ed301845773521997f9446e8eac508f16 /src/cmd/go/internal/get/get.go
parent00753d52323c466b7c9f998a7ec3dd0b1d63366f (diff)
downloadgo-4c78d54fdd9ffc81c15ffc3c4a2946f89d4fca22.tar.gz
go-4c78d54fdd9ffc81c15ffc3c4a2946f89d4fca22.zip
cmd: disable *.go domains lookup in go get command
Using 'go get x.go' instead of 'go build x.go' or some other go command is a common mistake. By that mistake, a user gets a misleading error message about unsuccessful `x.go` domain lookup. This improvement handles such cases, by validating, whether the argument hasn't specified version, has .go suffix, and either has no slashes or such file locally exists. Handled both GOPATH and GOMOD modes. Fixes #38478 Change-Id: I583a4ef7f7ca8901deb07ebc811e2b3c0e828fa6 Reviewed-on: https://go-review.googlesource.com/c/go/+/229938 Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Jay Conrod <jayconrod@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/cmd/go/internal/get/get.go')
-rw-r--r--src/cmd/go/internal/get/get.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/cmd/go/internal/get/get.go b/src/cmd/go/internal/get/get.go
index f7b2fa96e8..d38350c2a8 100644
--- a/src/cmd/go/internal/get/get.go
+++ b/src/cmd/go/internal/get/get.go
@@ -193,8 +193,24 @@ func downloadPaths(patterns []string) []string {
for _, arg := range patterns {
if strings.Contains(arg, "@") {
base.Fatalf("go: cannot use path@version syntax in GOPATH mode")
+ continue
+ }
+
+ // Guard against 'go get x.go', a common mistake.
+ // Note that package and module paths may end with '.go', so only print an error
+ // if the argument has no slash or refers to an existing file.
+ if strings.HasSuffix(arg, ".go") {
+ if !strings.Contains(arg, "/") {
+ base.Errorf("go get %s: arguments must be package or module paths", arg)
+ continue
+ }
+ if fi, err := os.Stat(arg); err == nil && !fi.IsDir() {
+ base.Errorf("go get: %s exists as a file, but 'go get' requires package arguments", arg)
+ }
}
}
+ base.ExitIfErrors()
+
var pkgs []string
for _, m := range search.ImportPathsQuiet(patterns) {
if len(m.Pkgs) == 0 && strings.Contains(m.Pattern(), "...") {