Skip to content

Commit bffea87

Browse files
committed
fixup! mingw: Support git_terminal_prompt with more terminals
'xterm_prompt' is not xterm-specific, change function name and error messages to reflect this. 'start_command' already prints an error message on failure, we don't need another one. Also print the script's exit code on failure. Signed-off-by: Karsten Blees <[email protected]>
1 parent 297b780 commit bffea87

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

compat/terminal.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static int disable_echo(void)
9494
return 0;
9595
}
9696

97-
static char *xterm_prompt(const char *prompt, int echo)
97+
static char *shell_prompt(const char *prompt, int echo)
9898
{
9999
const char *read_input[] = {
100100
/* Note: call 'bash' explicitly, as 'read -s' is bash-specific */
@@ -111,14 +111,11 @@ static char *xterm_prompt(const char *prompt, int echo)
111111
child.in = -1;
112112
child.out = -1;
113113

114-
code = start_command(&child);
115-
if (code) {
116-
error("Could not access xterm");
117-
goto ret;
118-
}
114+
if (start_command(&child))
115+
return NULL;
119116

120117
if (write_in_full(child.in, prompt, prompt_len) != prompt_len) {
121-
error("Could not write to xterm");
118+
error("could not write to prompt script");
122119
close(child.in);
123120
goto ret;
124121
}
@@ -127,7 +124,7 @@ static char *xterm_prompt(const char *prompt, int echo)
127124
strbuf_reset(&buffer);
128125
len = strbuf_read(&buffer, child.out, 1024);
129126
if (len < 0) {
130-
error("Could not read from xterm");
127+
error("could not read from prompt script");
131128
goto ret;
132129
}
133130

@@ -136,8 +133,11 @@ static char *xterm_prompt(const char *prompt, int echo)
136133

137134
ret:
138135
close(child.out);
139-
if (!code)
140-
finish_command(&child);
136+
code = finish_command(&child);
137+
if (code) {
138+
error("failed to execute prompt script (exit code %d)", code);
139+
return NULL;
140+
}
141141

142142
return len < 0 ? NULL : buffer.buf;
143143
}
@@ -157,7 +157,7 @@ char *git_terminal_prompt(const char *prompt, int echo)
157157
const char *term = getenv("TERM");
158158

159159
if (term && starts_with(term, "xterm"))
160-
return xterm_prompt(prompt, echo);
160+
return shell_prompt(prompt, echo);
161161
#endif
162162

163163
input_fh = fopen(INPUT_PATH, "r" FORCE_TEXT);

0 commit comments

Comments
 (0)