]> git.ipfire.org Git - thirdparty/git.git/commitdiff
add--interactive: handle EOF in prompt_yesno
authorJeff King <peff@peff.net>
Wed, 21 Jun 2017 19:26:36 +0000 (15:26 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 21 Jun 2017 21:06:09 +0000 (14:06 -0700)
The prompt_yesno function loops indefinitely waiting for a
"y" or "n" response. But it doesn't handle EOF, meaning
that we can end up in an infinite loop of reading EOF from
stdin. One way to simulate that is with:

  echo e | GIT_EDITOR='echo corrupt >' git add -p

Let's break out of the loop and propagate the undef to the
caller. Without modifying the callers that effectively turns
it into a "no" response. This is reasonable for both of the
current callers, and it leaves room for any future caller to
check for undef explicitly.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-add--interactive.perl

index 4e0ab5a9bc2f8b22fb7e358b162ebaa93c55e139..7c953247379c77bf49fd6806648bfee99c134471 100755 (executable)
@@ -1152,6 +1152,7 @@ sub prompt_yesno {
        while (1) {
                print colored $prompt_color, $prompt;
                my $line = prompt_single_character;
+               return undef unless defined $line;
                return 0 if $line =~ /^n/i;
                return 1 if $line =~ /^y/i;
        }