@@ -420,6 +420,55 @@ static int getchar_with_timeout(int timeout)
420
420
return getchar ();
421
421
}
422
422
423
+ static char * shell_prompt (const char * prompt , int echo )
424
+ {
425
+ const char * read_input [] = {
426
+ /* Note: call 'bash' explicitly, as 'read -s' is bash-specific */
427
+ "bash" , "-c" , echo ?
428
+ "cat >/dev/tty && read -r line </dev/tty && echo \"$line\"" :
429
+ "cat >/dev/tty && read -r -s line </dev/tty && echo \"$line\" && echo >/dev/tty" ,
430
+ NULL
431
+ };
432
+ struct child_process child = CHILD_PROCESS_INIT ;
433
+ static struct strbuf buffer = STRBUF_INIT ;
434
+ int prompt_len = strlen (prompt ), len = -1 , code ;
435
+
436
+ strvec_pushv (& child .args , read_input );
437
+ child .in = -1 ;
438
+ child .out = -1 ;
439
+ child .silent_exec_failure = 1 ;
440
+
441
+ if (start_command (& child ))
442
+ return NULL ;
443
+
444
+ if (write_in_full (child .in , prompt , prompt_len ) != prompt_len ) {
445
+ error ("could not write to prompt script" );
446
+ close (child .in );
447
+ goto ret ;
448
+ }
449
+ close (child .in );
450
+
451
+ strbuf_reset (& buffer );
452
+ len = strbuf_read (& buffer , child .out , 1024 );
453
+ if (len < 0 ) {
454
+ error ("could not read from prompt script" );
455
+ goto ret ;
456
+ }
457
+
458
+ strbuf_strip_suffix (& buffer , "\n" );
459
+ strbuf_strip_suffix (& buffer , "\r" );
460
+
461
+ ret :
462
+ close (child .out );
463
+ code = finish_command (& child );
464
+ if (code ) {
465
+ error ("failed to execute prompt script (exit code %d)" , code );
466
+ return NULL ;
467
+ }
468
+
469
+ return len < 0 ? NULL : buffer .buf ;
470
+ }
471
+
423
472
#endif
424
473
425
474
#ifndef FORCE_TEXT
@@ -432,6 +481,15 @@ char *git_terminal_prompt(const char *prompt, int echo)
432
481
int r ;
433
482
FILE * input_fh , * output_fh ;
434
483
484
+ #ifdef GIT_WINDOWS_NATIVE
485
+
486
+ /* try shell_prompt first, fall back to CONIN/OUT if bash is missing */
487
+ char * result = shell_prompt (prompt , echo );
488
+ if (result )
489
+ return result ;
490
+
491
+ #endif
492
+
435
493
input_fh = fopen (INPUT_PATH , "r" FORCE_TEXT );
436
494
if (!input_fh )
437
495
return NULL ;
0 commit comments