]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/vendor: create modules.txt even for unused deps
authorJoshua Crowgey <jcrowgey@uw.edu>
Thu, 13 Feb 2020 06:02:10 +0000 (06:02 +0000)
committerBryan C. Mills <bcmills@google.com>
Wed, 26 Feb 2020 14:31:35 +0000 (14:31 +0000)
`go mod vendor`  should create vendor/modules.txt even when the only deps
in go.mod are unused.

Fixes: #36580
Change-Id: I92a746d3f013bc2bdc3d2cec6e14b16f606c2edd
GitHub-Last-Rev: ea39a1c62294f42e5e5aab049f466189de0fd42d
GitHub-Pull-Request: golang/go#36920
Reviewed-on: https://go-review.googlesource.com/c/go/+/217135
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/vendor.go
src/cmd/go/testdata/script/mod_vendor_unused_only.txt [new file with mode: 0644]

index 0c00d1222e06ff7dfd362cf8f25dd0bb61dc286f..8509ceb7a8b948fab8a83bc1a00415e4ae955c5b 100644 (file)
@@ -123,6 +123,11 @@ func runVendor(cmd *base.Command, args []string) {
                fmt.Fprintf(os.Stderr, "go: no dependencies to vendor\n")
                return
        }
+
+       if err := os.MkdirAll(vdir, 0777); err != nil {
+               base.Fatalf("go mod vendor: %v", err)
+       }
+
        if err := ioutil.WriteFile(filepath.Join(vdir, "modules.txt"), buf.Bytes(), 0666); err != nil {
                base.Fatalf("go mod vendor: %v", err)
        }
diff --git a/src/cmd/go/testdata/script/mod_vendor_unused_only.txt b/src/cmd/go/testdata/script/mod_vendor_unused_only.txt
new file mode 100644 (file)
index 0000000..839c645
--- /dev/null
@@ -0,0 +1,17 @@
+# Ensure that we generate a vendor/modules.txt file even when the only
+# requirements in go.mod are unused.  Regression test for
+# golang.org/issue/36580
+
+env GO111MODULE=on
+
+go mod vendor
+cmp go1.14-modules.txt vendor/modules.txt
+
+-- go.mod --
+module example.com/m
+go 1.14
+
+require example.com v1.0.0 // indirect
+-- go1.14-modules.txt --
+# example.com v1.0.0
+## explicit