Skip to content

Commit cc2b667

Browse files
kbleesdscho
authored andcommitted
compat/terminal.c: only use the Windows console if bash 'read -r' fails
Accessing the Windows console through the special CONIN$ / CONOUT$ devices doesn't work properly for non-ASCII usernames an passwords. It also doesn't work for terminal emulators that hide the native console window (such as mintty), and 'TERM=xterm*' is not necessarily a reliable indicator for such terminals. The new shell_prompt() function, on the other hand, works fine for both MSys1 and MSys2, in native console windows as well as mintty, and properly supports Unicode. It just needs bash on the path (for 'read -s', which is bash-specific). On Windows, try to use the shell to read from the terminal. If that fails with ENOENT (i.e. bash was not found), use CONIN/OUT as fallback. Note: To test this, create a UTF-8 credential file with non-ASCII chars, e.g. in git-bash: 'echo url=http://täst.com > cred.txt'. Then in git-cmd, 'git credential fill <cred.txt' works (shell version), while calling git without the git-wrapper (i.e. 'mingw64\bin\git credential fill <cred.txt') mangles non-ASCII chars in both console output and input. Signed-off-by: Karsten Blees <[email protected]>
1 parent 4104681 commit cc2b667

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

compat/terminal.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ static char *shell_prompt(const char *prompt, int echo)
435435
strvec_pushv(&child.args, read_input);
436436
child.in = -1;
437437
child.out = -1;
438+
child.silent_exec_failure = 1;
438439

439440
if (start_command(&child))
440441
return NULL;
@@ -478,11 +479,14 @@ char *git_terminal_prompt(const char *prompt, int echo)
478479
static struct strbuf buf = STRBUF_INIT;
479480
int r;
480481
FILE *input_fh, *output_fh;
482+
481483
#ifdef GIT_WINDOWS_NATIVE
482-
const char *term = getenv("TERM");
483484

484-
if (term && starts_with(term, "xterm"))
485-
return shell_prompt(prompt, echo);
485+
/* try shell_prompt first, fall back to CONIN/OUT if bash is missing */
486+
char *result = shell_prompt(prompt, echo);
487+
if (result || errno != ENOENT)
488+
return result;
489+
486490
#endif
487491

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

0 commit comments

Comments
 (0)