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