cmd/go: skip vgo.Init for the version subcommand
Fixes golang/go#25903.
Change-Id: Ib3bcb90147cf5b452f41850aba733144e22c06f3
Reviewed-on: https://go-review.googlesource.com/119275
Reviewed-by: Russ Cox <rsc@golang.org>
diff --git a/vendor/cmd/go/main.go b/vendor/cmd/go/main.go
index 7327ef1..1190808 100644
--- a/vendor/cmd/go/main.go
+++ b/vendor/cmd/go/main.go
@@ -128,6 +128,9 @@
case "mod":
// Skip vgo.Init (which may insist on go.mod existing)
// so that go mod -init has a chance to write the file.
+ case "version":
+ // Skip vgo.Init so that users can report bugs against
+ // go mod -init.
case "vendor":
fmt.Fprintf(os.Stderr, "go vendor is now go mod -vendor\n")
os.Exit(2)
diff --git a/vendor/cmd/go/vgo_test.go b/vendor/cmd/go/vgo_test.go
index a2f61dd..983ff2e 100644
--- a/vendor/cmd/go/vgo_test.go
+++ b/vendor/cmd/go/vgo_test.go
@@ -624,3 +624,12 @@
tg.run("-vgo", "mod", "-vendor")
tg.grepStderr("vgo: no dependencies to vendor", "print vendor info")
}
+
+func TestVersionWithoutModule(t *testing.T) {
+ tg := testgo(t)
+ defer tg.cleanup()
+ tg.makeTempdir()
+
+ tg.cd(tg.path("."))
+ tg.run("-vgo", "version")
+}