2 #include "run-command.h"
5 #include "compat/terminal.h"
7 static char *do_askpass(const char *cmd, const char *prompt)
9 struct child_process pass = CHILD_PROCESS_INIT;
11 static struct strbuf buffer = STRBUF_INIT;
21 if (start_command(&pass))
24 strbuf_reset(&buffer);
25 if (strbuf_read(&buffer, pass.out, 20) < 0)
30 if (finish_command(&pass))
34 error("unable to read askpass response from '%s'", cmd);
35 strbuf_release(&buffer);
39 strbuf_setlen(&buffer, strcspn(buffer.buf, "\r\n"));
44 char *git_prompt(const char *prompt, int flags)
48 if (flags & PROMPT_ASKPASS) {
51 askpass = getenv("GIT_ASKPASS");
53 askpass = askpass_program;
55 askpass = getenv("SSH_ASKPASS");
56 if (askpass && *askpass)
57 r = do_askpass(askpass, prompt);
63 if (git_env_bool("GIT_TERMINAL_PROMPT", 1)) {
64 r = git_terminal_prompt(prompt, flags & PROMPT_ECHO);
65 err = strerror(errno);
67 err = "terminal prompts disabled";
70 /* prompts already contain ": " at the end */
71 die("could not read %s%s", prompt, err);
77 char *git_getpass(const char *prompt)
79 return git_prompt(prompt, PROMPT_ASKPASS);