mirror of
https://github.com/golang/go
synced 2024-11-17 07:54:41 -07:00
cmd/go/internal/modcmd: allow mod download without go.mod
Fixes #29522 Change-Id: I48f3a945d24c23c7c7ef5c7f1fe5046b6b2898e9 Reviewed-on: https://go-review.googlesource.com/c/go/+/157937 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
parent
1fd1408203
commit
a8d0047e47
@ -5,13 +5,14 @@
|
||||
package modcmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
"cmd/go/internal/base"
|
||||
"cmd/go/internal/modfetch"
|
||||
"cmd/go/internal/modload"
|
||||
"cmd/go/internal/module"
|
||||
"cmd/go/internal/par"
|
||||
"encoding/json"
|
||||
"os"
|
||||
)
|
||||
|
||||
var cmdDownload = &base.Command{
|
||||
|
@ -253,9 +253,11 @@ func Init() {
|
||||
func init() {
|
||||
load.ModInit = Init
|
||||
|
||||
// Set modfetch.PkgMod unconditionally, so that go clean -modcache can run even without modules enabled.
|
||||
// Set modfetch.PkgMod and codehost.WorkRoot unconditionally,
|
||||
// so that go clean -modcache and go mod download can run even without modules enabled.
|
||||
if list := filepath.SplitList(cfg.BuildContext.GOPATH); len(list) > 0 && list[0] != "" {
|
||||
modfetch.PkgMod = filepath.Join(list[0], "pkg/mod")
|
||||
codehost.WorkRoot = filepath.Join(list[0], "pkg/mod/cache/vcs")
|
||||
}
|
||||
}
|
||||
|
||||
|
7
src/cmd/go/testdata/script/mod_download.txt
vendored
7
src/cmd/go/testdata/script/mod_download.txt
vendored
@ -82,5 +82,12 @@ exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.3-pre1.zip
|
||||
go mod download -json rsc.io/quote@v1.5.1
|
||||
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.1.zip
|
||||
|
||||
# allow go mod download without go.mod
|
||||
env GO111MODULE=auto
|
||||
rm go.mod
|
||||
rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.2.1.zip
|
||||
go mod download rsc.io/quote@v1.2.1
|
||||
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.2.1.zip
|
||||
|
||||
-- go.mod --
|
||||
module m
|
||||
|
Loading…
Reference in New Issue
Block a user