Skip to content

Commit e56f6dc

Browse files
rscharfegitster
authored andcommitted
add-patch: quit on EOF
If we reach the end of the input, e.g. because the user pressed ctrl-D on Linux, there is no point in showing any more prompts, as we won't get any reply. Do the same as option 'q' would: Quit. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 1376811 commit e56f6dc

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

add-patch.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1569,8 +1569,10 @@ static int patch_update_file(struct add_p_state *s,
15691569
if (*s->s.reset_color_interactive)
15701570
fputs(s->s.reset_color_interactive, stdout);
15711571
fflush(stdout);
1572-
if (read_single_character(s) == EOF)
1572+
if (read_single_character(s) == EOF) {
1573+
quit = 1;
15731574
break;
1575+
}
15741576

15751577
if (!s->answer.len)
15761578
continue;

t/t3701-add-interactive.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,4 +1431,15 @@ test_expect_success 'invalid option s is rejected' '
14311431
test_cmp expect actual
14321432
'
14331433

1434+
test_expect_success 'EOF quits' '
1435+
echo a >file &&
1436+
echo a >file2 &&
1437+
git add file file2 &&
1438+
echo X >file &&
1439+
echo X >file2 &&
1440+
git add -p </dev/null >out &&
1441+
test_grep file out &&
1442+
test_grep ! file2 out
1443+
'
1444+
14341445
test_done

0 commit comments

Comments
 (0)