Skip to content

Commit e652c0e

Browse files
peffgitster
authored andcommitted
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>
1 parent 59b3865 commit e652c0e

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

Documentation/git.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,10 @@ for further details.
901901
and read the password from its STDOUT. See also the 'core.askpass'
902902
option in linkgit:git-config[1].
903903

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+
904908
'GIT_CONFIG_NOSYSTEM'::
905909
Whether to skip reading settings from the system-wide
906910
`$(prefix)/etc/gitconfig` file. This environment variable can

prompt.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,19 @@ char *git_prompt(const char *prompt, int flags)
5858
r = do_askpass(askpass, prompt);
5959
}
6060

61-
if (!r)
62-
r = git_terminal_prompt(prompt, flags & PROMPT_ECHO);
6361
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+
}
6674
}
6775
return r;
6876
}

0 commit comments

Comments
 (0)