Skip to content

Commit

Permalink
mingw (git_terminal_prompt): work around BusyBox & WSL issues
Browse files Browse the repository at this point in the history
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 <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Feb 23, 2018
1 parent 0dc4ae7 commit 7d45be2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions compat/terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,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 && echo \"$line\"" :
"cat >/dev/tty && read -r -s line </dev/tty && echo \"$line\" && echo >/dev/tty",
"test \"a$SHELL\" != \"a${SHELL%.exe}\" || exit 127; cat >/dev/tty &&"
" read -r line </dev/tty && echo \"$line\"" :
"test \"a$SHELL\" != \"a${SHELL%.exe}\" || exit 127; cat >/dev/tty &&"
" read -r -s line </dev/tty && echo \"$line\" && echo >/dev/tty",
NULL
};
struct child_process child = CHILD_PROCESS_INIT;
Expand Down Expand Up @@ -138,7 +140,10 @@ static char *shell_prompt(const char *prompt, int echo)
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;
}

Expand Down

0 comments on commit 7d45be2

Please sign in to comment.