Skip to content

Commit 040d9db

Browse files
committed
mingw (git_terminal_prompt): work around BusyBox & WSL issues
When trying to query the user directly via /dev/tty, both WSL's bash and BusyBox' bash emulation seem to have problems printing the value that they just read. The bash just stops in those instances, does not even execute any commands after the echo command. Let's just work around this by running the Bash snippet only in MSYS2's Bash: its `SHELL` variable has the `.exe` suffix, and neither WSL's nor BusyBox' bash set the `SHELL` variable to a path with that suffix. In the latter case, we simply exit with code 127 (indicating that the command was not found) and fall back to the CONIN$/CONOUT$ method quietly. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 98921b7 commit 040d9db

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

compat/terminal.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ static char *shell_prompt(const char *prompt, int echo)
101101
const char *read_input[] = {
102102
/* Note: call 'bash' explicitly, as 'read -s' is bash-specific */
103103
"bash", "-c", echo ?
104-
"cat >/dev/tty && read -r line </dev/tty && echo \"$line\"" :
105-
"cat >/dev/tty && read -r -s line </dev/tty && echo \"$line\" && echo >/dev/tty",
104+
"test \"a$SHELL\" != \"a${SHELL%.exe}\" || exit 127; cat >/dev/tty &&"
105+
" read -r line </dev/tty && echo \"$line\"" :
106+
"test \"a$SHELL\" != \"a${SHELL%.exe}\" || exit 127; cat >/dev/tty &&"
107+
" read -r -s line </dev/tty && echo \"$line\" && echo >/dev/tty",
106108
NULL
107109
};
108110
struct child_process child = CHILD_PROCESS_INIT;
@@ -138,7 +140,10 @@ static char *shell_prompt(const char *prompt, int echo)
138140
close(child.out);
139141
code = finish_command(&child);
140142
if (code) {
141-
error("failed to execute prompt script (exit code %d)", code);
143+
if (code != 127)
144+
error("failed to execute prompt script (exit code %d)",
145+
code);
146+
142147
return NULL;
143148
}
144149

0 commit comments

Comments
 (0)