cmd/vendor: create modules.txt even for unused deps

`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: ea39a1c622
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>
This commit is contained in:
Joshua Crowgey 2020-02-13 06:02:10 +00:00 committed by Bryan C. Mills
parent cb74dcc172
commit 26aadfa044
2 changed files with 22 additions and 0 deletions

View 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)
}

View File

@ -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