Skip to content

Commit a8bec7a

Browse files
peffgitster
authored andcommitted
add--interactive: leave main loop on read error
The main hunk loop for add--interactive will loop if it does not get a known input. This is a good thing if the user typed some invalid input. However, if we have an uncorrectable read error, we'll end up looping infinitely. We can fix this by noticing read errors (i.e., <STDIN> returns undef) and breaking out of the loop. One easy way to trigger this is if you have an editor that does not take over the terminal (e.g., one that spawns a window in an existing process and waits), start the editor with the hunk-edit command, and hit ^C to send SIGINT. The editor process dies due to SIGINT, but the perl add--interactive process does not (perl suspends SIGINT for the duration of our system() call). We return to the main loop, but further reads from stdin don't work. The SIGINT _also_ killed our parent git process, which orphans our process group, meaning that further reads from the terminal will always fail. We loop infinitely, getting EIO on each read. Note that there are several other spots where we read from stdin, too. However, in each of those cases, we do something sane when the read returns undef (breaking out of the loop, taking the input as "no", etc). They don't need similar treatment. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 76f8611 commit a8bec7a

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

git-add--interactive.perl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,7 @@ sub patch_update_file {
13561356
$patch_mode_flavour{TARGET},
13571357
" [y,n,q,a,d,/$other,?]? ";
13581358
my $line = prompt_single_character;
1359+
last unless defined $line;
13591360
if ($line) {
13601361
if ($line =~ /^y/i) {
13611362
$hunk[$ix]{USE} = 1;

0 commit comments

Comments
 (0)