]> git.ipfire.org Git - thirdparty/git.git/commitdiff
add-patch: quit on EOF
authorRené Scharfe <l.s.r@web.de>
Sat, 25 Oct 2025 05:48:28 +0000 (07:48 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sun, 26 Oct 2025 23:34:39 +0000 (16:34 -0700)
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>
add-patch.c
t/t3701-add-interactive.sh

index a70def1f81fe3f10902318f78e82cf45d5e2a636..173a53241ebf07b1cfde0988a4d3ac7330d22b6d 100644 (file)
@@ -1569,8 +1569,10 @@ static int patch_update_file(struct add_p_state *s,
                if (*s->s.reset_color_interactive)
                        fputs(s->s.reset_color_interactive, stdout);
                fflush(stdout);
-               if (read_single_character(s) == EOF)
+               if (read_single_character(s) == EOF) {
+                       quit = 1;
                        break;
+               }
 
                if (!s->answer.len)
                        continue;
index 851ca6dd91a9cad2a87a73d6495867f46ad7286f..4285314f35f8f20ec724c251928d1087e5c626b8 100755 (executable)
@@ -1431,4 +1431,15 @@ test_expect_success 'invalid option s is rejected' '
        test_cmp expect actual
 '
 
+test_expect_success 'EOF quits' '
+       echo a >file &&
+       echo a >file2 &&
+       git add file file2 &&
+       echo X >file &&
+       echo X >file2 &&
+       git add -p </dev/null >out &&
+       test_grep file out &&
+       test_grep ! file2 out
+'
+
 test_done