3 #include "run-command.h"
6 #include "compat/terminal.h"
8 static char *do_askpass(const char *cmd
, const char *prompt
)
10 struct child_process pass
= CHILD_PROCESS_INIT
;
11 static struct strbuf buffer
= STRBUF_INIT
;
14 strvec_push(&pass
.args
, cmd
);
15 strvec_push(&pass
.args
, prompt
);
19 if (start_command(&pass
))
22 strbuf_reset(&buffer
);
23 if (strbuf_read(&buffer
, pass
.out
, 20) < 0)
28 if (finish_command(&pass
))
32 error("unable to read askpass response from '%s'", cmd
);
33 strbuf_release(&buffer
);
37 strbuf_setlen(&buffer
, strcspn(buffer
.buf
, "\r\n"));
42 char *git_prompt(const char *prompt
, int flags
)
46 if (flags
& PROMPT_ASKPASS
) {
49 askpass
= getenv("GIT_ASKPASS");
51 askpass
= askpass_program
;
53 askpass
= getenv("SSH_ASKPASS");
54 if (askpass
&& *askpass
)
55 r
= do_askpass(askpass
, prompt
);
61 if (git_env_bool("GIT_TERMINAL_PROMPT", 1)) {
62 r
= git_terminal_prompt(prompt
, flags
& PROMPT_ECHO
);
63 err
= strerror(errno
);
65 err
= "terminal prompts disabled";
68 /* prompts already contain ": " at the end */
69 die("could not read %s%s", prompt
, err
);
75 int git_read_line_interactively(struct strbuf
*line
)
80 ret
= strbuf_getline_lf(line
, stdin
);
82 strbuf_trim_trailing_newline(line
);