cmd/go: don't override GIT_TERMINAL_PROMPT

This CL keeps disallowing `go get` from falling to the prompt unless
user has set GIT_TERMINAL_PROMPT env variable. If GIT_TERMINAL_PROMPT
is set, go-get will not override its value and will prompt for
username/password in the case of GIT_TERMINAL_PROMPT=1.

Fixes #12706.

Change-Id: Ibd6b1100af6b04fb8114279cdcf608943e7765be
Reviewed-on: https://go-review.googlesource.com/16091
Reviewed-by: Andrew Gerrand <adg@golang.org>
diff --git a/src/cmd/go/get.go b/src/cmd/go/get.go
index 283de18..aac21a0 100644
--- a/src/cmd/go/get.go
+++ b/src/cmd/go/get.go
@@ -84,8 +84,12 @@
 	// Disable any prompting for passwords by Git.
 	// Only has an effect for 2.3.0 or later, but avoiding
 	// the prompt in earlier versions is just too hard.
-	// See golang.org/issue/9341.
-	os.Setenv("GIT_TERMINAL_PROMPT", "0")
+	// If user has explicitly set GIT_TERMINAL_PROMPT=1, keep
+	// prompting.
+	// See golang.org/issue/9341 and golang.org/issue/12706.
+	if v := os.Getenv("GIT_TERMINAL_PROMPT"); v == "" {
+		os.Setenv("GIT_TERMINAL_PROMPT", "0")
+	}
 
 	// Phase 1.  Download/update.
 	var stk importStack