]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modcmd: skip modules with empty version strings
authorJay Conrod <jayconrod@google.com>
Mon, 11 Nov 2019 19:24:00 +0000 (14:24 -0500)
committerBryan C. Mills <bcmills@google.com>
Mon, 11 Nov 2019 20:19:06 +0000 (20:19 +0000)
This CL restores behavior before CL 189797 and fixes a misleading
comment. modload.ListModules may return info without a version for the
main module and for modules replaced with local directories.

Fixes #35505

Change-Id: I5b4e68053a680ff897b072fdf6e7aa17b6e1ac34
Reviewed-on: https://go-review.googlesource.com/c/go/+/206538
Run-TryBot: Jay Conrod <jayconrod@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/testdata/script/mod_download_replace_file.txt [new file with mode: 0644]

index 6ea18ea8729a02582ed951d209682c4db9cc0b3f..768ce94f39b9a9327575055d0719b9bffd222b93 100644 (file)
@@ -89,7 +89,7 @@ func runDownload(cmd *base.Command, args []string) {
                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")
+                               os.Stderr.WriteString("go mod download: skipping argument " + arg + " that resolves to the main module\n")
                        }
                }
        }
@@ -102,9 +102,9 @@ func runDownload(cmd *base.Command, args []string) {
                if info.Replace != nil {
                        info = info.Replace
                }
-               if (module.Version{Path: info.Path, Version: info.Version} == modload.Target) {
-                       // skipping main module.
-                       // go mod download without dependencies is silent.
+               if info.Version == "" && info.Error == nil {
+                       // main module or module replaced with file path.
+                       // Nothing to download.
                        continue
                }
                m := &moduleJSON{
diff --git a/src/cmd/go/testdata/script/mod_download_replace_file.txt b/src/cmd/go/testdata/script/mod_download_replace_file.txt
new file mode 100644 (file)
index 0000000..f6ab4fe
--- /dev/null
@@ -0,0 +1,16 @@
+# This test checks that 'go mod download' produces no output for
+# the main module (when specified implicitly) and for a module replaced
+# with a file path.
+# Verifies golang.org/issue/35505.
+go mod download -json all
+cmp stdout no-output
+
+-- go.mod --
+module example.com/a
+
+require example.com/b v1.0.0
+
+replace example.com/b => ./local/b
+-- local/b/go.mod --
+module example.com/b
+-- no-output --