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>
René Scharfe committed
Oct 25, 2025 at 07:48 UTC
e56f6dcd7b4c90192018e848d0810f091d092913
2 files changed
+14
-1
add-patch.c
+3
-1
@@ -1569,8 +1569,10 @@ static int patch_update_file(struct add_p_state *s,
1569
if (*s->s.reset_color_interactive)
1570
fputs(s->s.reset_color_interactive, stdout);
1571
fflush(stdout);
1572
- if (read_single_character(s) == EOF)
1572
+ if (read_single_character(s) == EOF) {
1573
+ quit = 1;
1574
break;
1575
+ }
1576
1577
if (!s->answer.len)
1578
continue;
t/t3701-add-interactive.sh
+11
@@ -1431,4 +1431,15 @@ test_expect_success 'invalid option s is rejected' '
1431
test_cmp expect actual
1432
'
1433
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
+
1445
test_done