From 87d17ee89253ac0b9308bcadc7a6d87decc29fb0 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 23 Feb 2018 02:50:03 +0100 Subject: [PATCH] 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 --- compat/terminal.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/compat/terminal.c b/compat/terminal.c index 1d37f0aafb..f3eb1b54f9 100644 --- a/compat/terminal.c +++ b/compat/terminal.c @@ -99,8 +99,10 @@ static char *shell_prompt(const char *prompt, int echo) const char *read_input[] = { /* Note: call 'bash' explicitly, as 'read -s' is bash-specific */ "bash", "-c", echo ? - "cat >/dev/tty && read -r line /dev/tty && read -r -s line /dev/tty", + "test \"a$SHELL\" != \"a${SHELL%.exe}\" || exit 127; cat >/dev/tty &&" + " read -r line /dev/tty &&" + " read -r -s line /dev/tty", NULL }; struct child_process child = CHILD_PROCESS_INIT; @@ -136,7 +138,10 @@ ret: close(child.out); code = finish_command(&child); if (code) { - error("failed to execute prompt script (exit code %d)", code); + if (code != 127) + error("failed to execute prompt script (exit code %d)", + code); + return NULL; }