git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] add--interactive: handle EOF in prompt_yesno

From
Jeff King <peff@peff.net>
Date
Jun 21, 2017, 19:26 UTC
Message-ID
<20170621192636.e5odne2lojuq63gm@sigill.intra.peff.net>
In-Reply-To
<20170621192315.3umx4lszvzwjffnb@sigill.intra.peff.net>

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>
---
 git-add--interactive.perl | 1 +
 1 file changed, 1 insertion(+)
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 79d675b5b..fc722fe8a 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -1136,6 +1136,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;
 	}
-- 
2.13.1.792.g159074dab
Previous: Jeff KingNext: Jeff King
Message 4 of 6 in “git add -p does not work with custom comment char currently”
  1. Christian RöschJun 21, 2017
  2. Jeff KingJun 21, 2017
  3. 0/2 Re: git add -p does not work with custom comment char currentlyJeff King, Jun 21, 2017
  4. 1/2 add--interactive: handle EOF in prompt_yesnoJeff King, Jun 21, 2017
  5. 2/2 add--interactive: quote commentChar regexJeff King, Jun 21, 2017
  6. Christian RöschJun 21, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.