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
);
61 r
= git_terminal_prompt(prompt
, flags
& PROMPT_ECHO
);
63 /* prompts already contain ": " at the end */
64 die("could not read %s%s", prompt
, strerror(errno
));
69 char *git_getpass(const char *prompt
)
71 return git_prompt(prompt
, PROMPT_ASKPASS
);