Skip to content

Commit 97387c8

Browse files
peffgitster
authored andcommitted
am: read interactive input from stdin
In the conversion of git-am from shell script to C, we switched to using git_prompt(). Unlike the original shell command "read reply", this doesn't read from stdin at all, but rather from /dev/tty. In most cases this distinction wouldn't matter. We require (as the shell script did) that stdin is a tty, so they would generally be the same thing. But one important exception is our test suite: even with test_terminal, we cannot test "am --interactive" because it insists on reading from /dev/tty, not the pseudo-tty we've set up in the test script. Fixing this clears the way to adding tests in a future patch. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1db65f3 commit 97387c8

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

builtin/am.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,7 @@ static int do_interactive(struct am_state *state)
16441644
die(_("cannot be interactive without stdin connected to a terminal."));
16451645

16461646
for (;;) {
1647-
const char *reply;
1647+
char reply[64];
16481648

16491649
puts(_("Commit Body is:"));
16501650
puts("--------------------------");
@@ -1656,7 +1656,9 @@ static int do_interactive(struct am_state *state)
16561656
* in your translation. The program will only accept English
16571657
* input at this point.
16581658
*/
1659-
reply = git_prompt(_("Apply? [y]es/[n]o/[e]dit/[v]iew patch/[a]ccept all: "), PROMPT_ECHO);
1659+
printf(_("Apply? [y]es/[n]o/[e]dit/[v]iew patch/[a]ccept all: "));
1660+
if (!fgets(reply, sizeof(reply), stdin))
1661+
die("unable to read from stdin; aborting");
16601662

16611663
if (*reply == 'y' || *reply == 'Y') {
16621664
return 0;

0 commit comments

Comments
 (0)