base.Fatalf("go: -insecure flag is no longer supported; use GOINSECURE instead")
}
+ modload.ForceUseModules = true
+
// Do not allow any updating of go.mod until we've applied
// all the requested changes and checked that the result matches
// what was requested.
// 'go get' is expected to do this, unlike other commands.
modload.AllowMissingModuleImports()
+ // 'go get' no longer builds or installs packages, so there's nothing to do
+ // if there's no go.mod file.
+ // TODO(#40775): make modload.Init return ErrNoModRoot instead of exiting.
+ // We could handle that here by printing a different message.
+ modload.Init()
+ if !modload.HasModRoot() {
+ base.Fatalf("go: go.mod file not found in current directory or any parent directory.\n" +
+ "\t'go get' is no longer supported outside a module.\n" +
+ "\tTo build and install a command, use 'go install' with a version,\n" +
+ "\tlike 'go install example.com/cmd@latest'\n" +
+ "\tFor more information, see https://golang.org/doc/go-get-install-deprecation\n" +
+ "\tor run 'go help get' or 'go help install'.")
+ }
+
queries := parseArgs(ctx, args)
r := newResolver(ctx, queries)
}
r.checkPackageProblems(ctx, pkgPatterns)
- if !modload.HasModRoot() {
- return
- }
-
// Everything succeeded. Update go.mod.
oldReqs := reqsFromGoMod(modload.ModFile())
env GO111MODULE=on
env GOPROXY=direct
go get -d bazil.org/fuse/fs/fstestutil
+
+
+-- go.mod --
+module m
+
+go 1.18
# Go should reject relative paths in GOMODCACHE environment.
env GOMODCACHE="~/test"
-! go get example.com/tools/cmd/hello
+! go install example.com/tools/cmd/hello@latest
stderr 'must be absolute path'
env GOMODCACHE="./test"
-! go get example.com/tools/cmd/hello
+! go install example.com/tools/cmd/hello@latest
stderr 'must be absolute path'
env GOPROXY=direct
env GOSUMDB=off
-! go get -d vcs-test.golang.org/insecure/go/insecure
+! go mod download vcs-test.golang.org/insecure/go/insecure@latest
stderr 'redirected .* to insecure URL'
# insecure host
env GOINSECURE=vcs-test.golang.org
go clean -modcache
-go get -d vcs-test.golang.org/insecure/go/insecure
+go mod download vcs-test.golang.org/insecure/go/insecure@latest
# insecure glob host
env GOINSECURE=*.golang.org
go clean -modcache
-go get -d vcs-test.golang.org/insecure/go/insecure
+go mod download vcs-test.golang.org/insecure/go/insecure@latest
# insecure multiple host
env GOINSECURE=somewhere-else.com,*.golang.org
go clean -modcache
-go get -d vcs-test.golang.org/insecure/go/insecure
+go mod download vcs-test.golang.org/insecure/go/insecure@latest
# different insecure host does not fetch
env GOINSECURE=somewhere-else.com
go clean -modcache
-! go get -d vcs-test.golang.org/insecure/go/insecure
+! go mod download vcs-test.golang.org/insecure/go/insecure@latest
stderr 'redirected .* to insecure URL'
[!exec:git] skip
env GOPROXY=direct
-! go get github.com/golang/nonexist
+! go mod download github.com/golang/nonexist@latest
stderr 'Confirm the import path was entered correctly.'
stderr 'If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.'
! stdout .
# Fetching a nonexistent commit should return an "unknown revision"
# error message.
-! go get github.com/golang/term@86186f3aba07ed0212cfb944f3398997d2d07c6b
+! go mod download github.com/golang/term@86186f3aba07ed0212cfb944f3398997d2d07c6b
stderr '^go: github.com/golang/term@86186f3aba07ed0212cfb944f3398997d2d07c6b: invalid version: unknown revision 86186f3aba07ed0212cfb944f3398997d2d07c6b$'
! stdout .
-! go get github.com/golang/nonexist@master
+! go mod download github.com/golang/nonexist@master
stderr '^Confirm the import path was entered correctly.$'
stderr '^If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.$'
! stderr 'unknown revision'
env GOPROXY=$GOPROXYBASE/redirect/11
env GOSUMDB=off
-! go get -d rsc.io/quote@v1.2.0
+! go mod download rsc.io/quote@v1.2.0
stderr 'stopped after 10 redirects'
env GOPROXY=$GOPROXYBASE/redirect/9
-go get -d rsc.io/quote@v1.2.0
+go mod download rsc.io/quote@v1.2.0
env GO111MODULE=on
-# TODO(#43684): test message outside module.
+# 'go get' outside a module prints an error.
+! go get example.com/cmd/a
+stderr '^go: go.mod file not found in current directory or any parent directory.$'
+stderr '^\t''go get'' is no longer supported outside a module.$'
cp go.mod.orig go.mod
go get -x -v -d golang.org/x/tools/cmd/goimports
stderr '# get https://proxy.golang.org/golang.org/x/tools/@v/list'
! stderr '# get https://golang.org'
+
+-- go.mod --
+module m
+
+go 1.18
rm test/test_dir.go
+-- go.mod --
+module m
+
+go 1.18
+
-- test.go --
package main
func main() {println("test")}
stderr '^# get https://golang.org/x/text\?go-get=1$'
stderr '^# get https://golang.org/x/text\?go-get=1: 200 OK \([0-9.]+s\)$'
! stderr '^# get //.*'
+
+-- go.mod --
+module m
+
+go 1.18
env GOPROXY=direct
env GOSUMDB=off
-! go get -d vcs-test.golang.org/go/missingrepo/missingrepo-git
+! go mod download vcs-test.golang.org/go/missingrepo/missingrepo-git@latest
stderr 'vcs-test.golang.org/go/missingrepo/missingrepo-git: git ls-remote .*: exit status .*'
-go get -d vcs-test.golang.org/go/missingrepo/missingrepo-git/notmissing
+go mod download vcs-test.golang.org/go/missingrepo/missingrepo-git/notmissing@latest
stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$'
-# 'go get' without arguments implicitly operates on the main module, and thus
-# should fail.
+# 'go get' has no go.mod file to update outside a module and should fail.
! go get
-stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$'
+stderr '^go: go.mod file not found in current directory or any parent directory.$'
+stderr '^\t''go get'' is no longer supported outside a module.$'
! go get -u
-stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$'
+stderr '^go: go.mod file not found in current directory or any parent directory.$'
+stderr '^\t''go get'' is no longer supported outside a module.$'
! go get -u ./needmod
-stderr '^go: go.mod file not found in current directory or any parent directory; see ''go help modules''$'
-
-# 'go get -u all' upgrades the transitive import graph of the main module,
-# which is empty.
+stderr '^go: go.mod file not found in current directory or any parent directory.$'
+stderr '^\t''go get'' is no longer supported outside a module.$'
! go get -u all
-stderr '^go: cannot match "all": go.mod file not found in current directory or any parent directory; see ''go help modules''$'
-
-# 'go get' should check the proposed module graph for consistency,
-# even though we won't write it anywhere.
+stderr '^go: go.mod file not found in current directory or any parent directory.$'
+stderr '^\t''go get'' is no longer supported outside a module.$'
! go get -d example.com/printversion@v1.0.0 example.com/version@none
-stderr '^go: example.com/printversion@v1.0.0 requires example.com/version@v1.0.0, not example.com/version@none$'
-
-# 'go get -d' should download and extract the source code needed to build the requested version.
-rm -r $GOPATH/pkg/mod/example.com
-go get -d example.com/printversion@v1.0.0
-exists $GOPATH/pkg/mod/example.com/printversion@v1.0.0
-exists $GOPATH/pkg/mod/example.com/version@v1.0.0
+stderr '^go: go.mod file not found in current directory or any parent directory.$'
+stderr '^\t''go get'' is no longer supported outside a module.$'
+
+# 'go get -d' should not download anything.
+go clean -modcache
+! go get -d example.com/printversion@v1.0.0
+stderr '^go: go.mod file not found in current directory or any parent directory.$'
+stderr '^\t''go get'' is no longer supported outside a module.$'
+! exists $GOPATH/pkg/mod/example.com/printversion@v1.0.0
+! exists $GOPATH/pkg/mod/example.com/version@v1.0.0
# 'go build' without arguments implicitly operates on the current directory, and should fail.