1 #define USE_THE_REPOSITORY_VARIABLE
3 #include "git-compat-util.h"
5 #include "environment.h"
6 #include "run-command.h"
9 #include "compat/terminal.h"
11 static char *do_askpass(const char *cmd
, const char *prompt
)
13 struct child_process pass
= CHILD_PROCESS_INIT
;
14 static struct strbuf buffer
= STRBUF_INIT
;
17 strvec_push(&pass
.args
, cmd
);
18 strvec_push(&pass
.args
, prompt
);
22 if (start_command(&pass
))
25 strbuf_reset(&buffer
);
26 if (strbuf_read(&buffer
, pass
.out
, 20) < 0)
31 if (finish_command(&pass
))
35 error("unable to read askpass response from '%s'", cmd
);
36 strbuf_release(&buffer
);
40 strbuf_setlen(&buffer
, strcspn(buffer
.buf
, "\r\n"));
45 char *git_prompt(const char *prompt
, int flags
)
49 if (flags
& PROMPT_ASKPASS
) {
52 askpass
= getenv("GIT_ASKPASS");
54 askpass
= askpass_program
;
56 askpass
= getenv("SSH_ASKPASS");
57 if (askpass
&& *askpass
)
58 r
= do_askpass(askpass
, prompt
);
64 if (git_env_bool("GIT_TERMINAL_PROMPT", 1)) {
65 r
= git_terminal_prompt(prompt
, flags
& PROMPT_ECHO
);
66 err
= strerror(errno
);
68 err
= "terminal prompts disabled";
71 /* prompts already contain ": " at the end */
72 die("could not read %s%s", prompt
, err
);
78 int git_read_line_interactively(struct strbuf
*line
)
83 ret
= strbuf_getline_lf(line
, stdin
);
85 strbuf_trim_trailing_newline(line
);