internal/gocommand: fix environment on Windows

Seems like os.Environ() is necessary after all. My bad for not testing
my earlier change on Windows. I'm not able to reproduce the behavior
in my test, so it's not really testing the crash correctly.

Fixes golang/go#38062

Change-Id: Ied45bbf572023a9dcd5d020db49bf3e95c824602
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226370
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
diff --git a/internal/gocommand/invoke.go b/internal/gocommand/invoke.go
index 1f5ee8c..ac80f10 100644
--- a/internal/gocommand/invoke.go
+++ b/internal/gocommand/invoke.go
@@ -1,3 +1,7 @@
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
 // Package gocommand is a helper for calling the go command.
 package gocommand
 
@@ -78,7 +82,7 @@
 	// The Go stdlib has a special feature where if the cwd and the PWD are the
 	// same node then it trusts the PWD, so by setting it in the env for the child
 	// process we fix up all the paths returned by the go command.
-	cmd.Env = append([]string{}, append(i.Env, cmd.Env...)...)
+	cmd.Env = append(os.Environ(), i.Env...)
 	if i.WorkingDir != "" {
 		cmd.Env = append(cmd.Env, "PWD="+i.WorkingDir)
 		cmd.Dir = i.WorkingDir
diff --git a/internal/gocommand/invoke_test.go b/internal/gocommand/invoke_test.go
new file mode 100644
index 0000000..ff50ea7
--- /dev/null
+++ b/internal/gocommand/invoke_test.go
@@ -0,0 +1,21 @@
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package gocommand_test
+
+import (
+	"context"
+	"testing"
+
+	"golang.org/x/tools/internal/gocommand"
+)
+
+func TestGoVersion(t *testing.T) {
+	inv := gocommand.Invocation{
+		Verb: "version",
+	}
+	if _, err := inv.Run(context.Background()); err != nil {
+		t.Error(err)
+	}
+}