2 #include "run-command.h"
6 char *git_getpass(const char *prompt
)
9 struct child_process pass
;
11 static struct strbuf buffer
= STRBUF_INIT
;
13 askpass
= getenv("GIT_ASKPASS");
15 askpass
= askpass_program
;
17 askpass
= getenv("SSH_ASKPASS");
18 if (!askpass
|| !(*askpass
)) {
19 char *result
= getpass(prompt
);
21 die_errno("Could not read password");
29 memset(&pass
, 0, sizeof(pass
));
33 if (start_command(&pass
))
36 strbuf_reset(&buffer
);
37 if (strbuf_read(&buffer
, pass
.out
, 20) < 0)
38 die("failed to read password from %s\n", askpass
);
42 if (finish_command(&pass
))
45 strbuf_setlen(&buffer
, strcspn(buffer
.buf
, "\r\n"));