2 #include "run-command.h"
6 static char *do_askpass(const char *cmd
, const char *prompt
)
8 struct child_process pass
;
10 static struct strbuf buffer
= STRBUF_INIT
;
16 memset(&pass
, 0, sizeof(pass
));
20 if (start_command(&pass
))
23 strbuf_reset(&buffer
);
24 if (strbuf_read(&buffer
, pass
.out
, 20) < 0)
25 die("failed to get '%s' from %s\n", prompt
, cmd
);
29 if (finish_command(&pass
))
32 strbuf_setlen(&buffer
, strcspn(buffer
.buf
, "\r\n"));
37 char *git_prompt(const char *prompt
, int flags
)
41 if (flags
& PROMPT_ASKPASS
) {
44 askpass
= getenv("GIT_ASKPASS");
46 askpass
= askpass_program
;
48 askpass
= getenv("SSH_ASKPASS");
49 if (askpass
&& *askpass
)
50 return do_askpass(askpass
, prompt
);
55 die_errno("could not read '%s'", prompt
);
59 char *git_getpass(const char *prompt
)
61 return git_prompt(prompt
, PROMPT_ASKPASS
);