Commit a8d0047e authored by Baokun Lee's avatar Baokun Lee Committed by Bryan C. Mills

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: default avatarBryan C. Mills <bcmills@google.com>
parent 1fd14082
......@@ -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")
}
}
......
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment