prompt: respect GIT_TERMINAL_PROMPT to disable terminal prompts
If you run git as part of an automated system, you might prefer git to die rather than try to issue a prompt on the terminal (because there would be nobody to see it and respond, and the process would hang forever). This usually works out of the box because getpass() (and our more featureful replacements) will fail when there is no tty, but this does not cover all cases. For example, a batch system run via ssh might have a tty, even when the user does not expect it. Let's provide an environment variable the user can set to avoid even trying to touch the tty at all. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Dec 3, 2014 at 22:52 UTC
e652c0eb5d772076f92245c7e076bf6aaf6af223
2 files changed
+16
-4
Documentation/git.txt
+4
@@ -901,6 +901,10 @@ for further details.
901
and read the password from its STDOUT. See also the 'core.askpass'
902
option in linkgit:git-config[1].
903
904
+'GIT_TERMINAL_PROMPT'::
905
+ If this environment variable is set to `0`, git will not prompt
906
+ on the terminal (e.g., when asking for HTTP authentication).
907
+
908
'GIT_CONFIG_NOSYSTEM'::
909
Whether to skip reading settings from the system-wide
910
`$(prefix)/etc/gitconfig` file. This environment variable can
prompt.c
+12
-4
@@ -58,11 +58,19 @@ char *git_prompt(const char *prompt, int flags)
58
r = do_askpass(askpass, prompt);
59
}
60
61
- if (!r)
62
- r = git_terminal_prompt(prompt, flags & PROMPT_ECHO);
61
if (!r) {
64
- /* prompts already contain ": " at the end */
65
- die("could not read %s%s", prompt, strerror(errno));
62
+ const char *err;
63
+
64
+ if (git_env_bool("GIT_TERMINAL_PROMPT", 1)) {
65
+ r = git_terminal_prompt(prompt, flags & PROMPT_ECHO);
66
+ err = strerror(errno);
67
+ } else {
68
+ err = "terminal prompts disabled";
69
+ }
70
+ if (!r) {
71
+ /* prompts already contain ": " at the end */
72
+ die("could not read %s%s", prompt, err);
73
+ }
74
}
75
return r;
76
}