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;
11 static struct strbuf buffer = STRBUF_INIT;
17 memset(&pass, 0, sizeof(pass));
21 if (start_command(&pass))
24 strbuf_reset(&buffer);
25 if (strbuf_read(&buffer, pass.out, 20) < 0)
26 die("failed to get '%s' from %s\n", prompt, cmd);
30 if (finish_command(&pass))
33 strbuf_setlen(&buffer, strcspn(buffer.buf, "\r\n"));
38 char *git_prompt(const char *prompt, int flags)
42 if (flags & PROMPT_ASKPASS) {
45 askpass = getenv("GIT_ASKPASS");
47 askpass = askpass_program;
49 askpass = getenv("SSH_ASKPASS");
50 if (askpass && *askpass)
51 return do_askpass(askpass, prompt);
54 r = git_terminal_prompt(prompt, flags & PROMPT_ECHO);
56 die_errno("could not read '%s'", prompt);
60 char *git_getpass(const char *prompt)
62 return git_prompt(prompt, PROMPT_ASKPASS);