cmd/go/internal/vgo: fix vendor fails without dependencies
Fixes golang/go#25843
Change-Id: I7044ce7cf0ddf8c852c7c0662b901b9102c6f1c1
Reviewed-on: https://go-review.googlesource.com/118235
Reviewed-by: Russ Cox <rsc@golang.org>
diff --git a/vendor/cmd/go/internal/vgo/vendor.go b/vendor/cmd/go/internal/vgo/vendor.go
index acba4af..f7000b2 100644
--- a/vendor/cmd/go/internal/vgo/vendor.go
+++ b/vendor/cmd/go/internal/vgo/vendor.go
@@ -84,6 +84,10 @@
}
}
}
+ if buf.Len() == 0 {
+ fmt.Fprintf(os.Stderr, "vgo: no dependencies to vendor\n")
+ return
+ }
if err := ioutil.WriteFile(filepath.Join(vdir, "vgo.list"), buf.Bytes(), 0666); err != nil {
base.Fatalf("vgo vendor: %v", err)
}
diff --git a/vendor/cmd/go/vgo_test.go b/vendor/cmd/go/vgo_test.go
index 694c150..b743f40 100644
--- a/vendor/cmd/go/vgo_test.go
+++ b/vendor/cmd/go/vgo_test.go
@@ -357,3 +357,16 @@
tg.mustNotExist(filepath.Join(tg.path("gp"), "/src/v/cache/github.com/pkg/errors/@v/v0.8.0.zip"))
tg.mustNotExist(filepath.Join(tg.path("gp"), "/src/v/github.com/pkg"))
}
+
+func TestVendorWithoutDeps(t *testing.T) {
+ tg := testgo(t)
+ defer tg.cleanup()
+ tg.makeTempdir()
+
+ tg.must(os.MkdirAll(tg.path("x"), 0777))
+ tg.must(ioutil.WriteFile(tg.path("x/main.go"), []byte(`package x`), 0666))
+ tg.must(ioutil.WriteFile(tg.path("x/go.mod"), []byte(`module x`), 0666))
+ tg.cd(tg.path("x"))
+ tg.run("-vgo", "vendor")
+ tg.grepStderr("vgo: no dependencies to vendor", "print vendor info")
+}