1
0
mirror of https://github.com/golang/go synced 2024-11-26 18:16:48 -07:00

cmd/go: disable password prompt when running git

This fix only works on Git 2.3.0 and later.

There appears to be no portable way to fix the earlier versions.
We already run git with stdin closed, but on Unix git calls getpass,
which opens /dev/tty itself. We could do package syscall-specific
things to get /dev/tty invalidated during the exec, but I'd really
rather not. And on Windows, Git opens "CONIN$" and "CONOUT$"
itself, and I have no idea how to invalidate those.

Fix the problem for newish Git versions and wait for people to update.
Best we can do.

Fixes #9341.

Change-Id: I576579b106764029853e0f74d411e19108deecf5
Reviewed-on: https://go-review.googlesource.com/12175
Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
Russ Cox 2015-07-14 01:22:53 -04:00
parent 3c9f60c99a
commit 8df0bcc1fb

View File

@ -77,6 +77,12 @@ func runGet(cmd *Command, args []string) {
fatalf("go get: cannot use -f flag without -u")
}
// 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")
// Phase 1. Download/update.
var stk importStack
for _, arg := range downloadPaths(args) {