1 #include "git-compat-util.h"
3 #include "environment.h"
4 #include "run-command.h"
7 #include "compat/terminal.h"
9 static char *do_askpass(const char *cmd
, const char *prompt
)
11 struct child_process pass
= CHILD_PROCESS_INIT
;
12 static struct strbuf buffer
= STRBUF_INIT
;
15 strvec_push(&pass
.args
, cmd
);
16 strvec_push(&pass
.args
, prompt
);
20 if (start_command(&pass
))
23 strbuf_reset(&buffer
);
24 if (strbuf_read(&buffer
, pass
.out
, 20) < 0)
29 if (finish_command(&pass
))
33 error("unable to read askpass response from '%s'", cmd
);
34 strbuf_release(&buffer
);
38 strbuf_setlen(&buffer
, strcspn(buffer
.buf
, "\r\n"));
43 char *git_prompt(const char *prompt
, int flags
)
47 if (flags
& PROMPT_ASKPASS
) {
50 askpass
= getenv("GIT_ASKPASS");
52 askpass
= askpass_program
;
54 askpass
= getenv("SSH_ASKPASS");
55 if (askpass
&& *askpass
)
56 r
= do_askpass(askpass
, prompt
);
62 if (git_env_bool("GIT_TERMINAL_PROMPT", 1)) {
63 r
= git_terminal_prompt(prompt
, flags
& PROMPT_ECHO
);
64 err
= strerror(errno
);
66 err
= "terminal prompts disabled";
69 /* prompts already contain ": " at the end */
70 die("could not read %s%s", prompt
, err
);
76 int git_read_line_interactively(struct strbuf
*line
)
81 ret
= strbuf_getline_lf(line
, stdin
);
83 strbuf_trim_trailing_newline(line
);