]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: error out of 'go mod download' if the main module is passed as argument
authorConstantin Konstantinidis <constantinkonstantinidis@gmail.com>
Sat, 10 Aug 2019 06:00:55 +0000 (08:00 +0200)
committerBryan C. Mills <bcmills@google.com>
Mon, 11 Nov 2019 15:37:55 +0000 (15:37 +0000)
Test added.

Fixes #28338

Change-Id: Iab72ba5646360ae91671261161d8fda451f7a717
Reviewed-on: https://go-review.googlesource.com/c/go/+/189797
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/cmd/go/internal/modcmd/download.go
src/cmd/go/testdata/script/mod_download.txt

index 1687cc57944121c87f0ec145e1fce6d34ed587fa..6ea18ea8729a02582ed951d209682c4db9cc0b3f 100644 (file)
@@ -81,6 +81,17 @@ func runDownload(cmd *base.Command, args []string) {
        }
        if len(args) == 0 {
                args = []string{"all"}
+       } else if modload.HasModRoot() {
+               modload.InitMod() // to fill Target
+               targetAtLatest := modload.Target.Path + "@latest"
+               targetAtUpgrade := modload.Target.Path + "@upgrade"
+               targetAtPatch := modload.Target.Path + "@patch"
+               for _, arg := range args {
+                       switch arg {
+                       case modload.Target.Path, targetAtLatest, targetAtUpgrade, targetAtPatch:
+                               os.Stderr.WriteString("go mod download: skipping argument "+ arg + " that resolves to the main module\n")
+                       }
+               }
        }
 
        var mods []*moduleJSON
@@ -91,8 +102,9 @@ func runDownload(cmd *base.Command, args []string) {
                if info.Replace != nil {
                        info = info.Replace
                }
-               if info.Version == "" && info.Error == nil {
-                       // main module
+               if (module.Version{Path: info.Path, Version: info.Version} == modload.Target) {
+                       // skipping main module.
+                       // go mod download without dependencies is silent.
                        continue
                }
                m := &moduleJSON{
index 07779137869f350063c69208e83bd83a7e13def4..e341222d60be93e8ec2e6aba20d5bec32f2fe380 100644 (file)
@@ -93,6 +93,12 @@ stderr '^rsc.io/quote@v1.999.999: reading .*/v1.999.999.info: 404 Not Found$'
 ! go mod download -json bad/path
 stdout '^\t"Error": "module bad/path: not a known dependency"'
 
+# download main module returns an error
+go mod download m
+stderr '^go mod download: skipping argument m that resolves to the main module\n'
+go mod download m@latest
+stderr '^go mod download: skipping argument m@latest that resolves to the main module\n'
+
 # allow go mod download without go.mod
 env GO111MODULE=auto
 rm go.mod