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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed May 20, 2019 at 08:09 UTC 97387c8bdd92596d79a84ce8a479c6b3c16d0cb7
1 file changed +4 -2
builtin/am.c
+4 -2
@@ -1644,7 +1644,7 @@ static int do_interactive(struct am_state *state)
1644 die(_("cannot be interactive without stdin connected to a terminal."));
1645
1646 for (;;) {
1647 - const char *reply;
1647 + char reply[64];
1648
1649 puts(_("Commit Body is:"));
1650 puts("--------------------------");
@@ -1656,7 +1656,9 @@ static int do_interactive(struct am_state *state)
1656 * in your translation. The program will only accept English
1657 * input at this point.
1658 */
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");
1662
1663 if (*reply == 'y' || *reply == 'Y') {
1664 return 0;