]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modcmd: allow mod download without go.mod
authorBaokun Lee <nototon@gmail.com>
Tue, 15 Jan 2019 10:53:44 +0000 (18:53 +0800)
committerBryan C. Mills <bcmills@google.com>
Tue, 30 Apr 2019 18:11:24 +0000 (18:11 +0000)
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>
src/cmd/go/internal/modcmd/download.go
src/cmd/go/internal/modload/init.go
src/cmd/go/testdata/script/mod_download.txt

index bbaba444f507f64c5ca647f559894a08b10eae5d..9f8c410b82f78b9e3619cd597922609b7682e4f8 100644 (file)
@@ -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{
index eaf4407529579cac12da0fa2a3cb85a9798775d0..ef2786109b69dfadb050d614bdf9a6a0ad490f79 100644 (file)
@@ -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")
        }
 }
 
index 38043b259742517d6c2535865849958dff9c6002..62b9eee54789474926cdfb94e4142cf3610ea517 100644 (file)
@@ -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