Merge branch 'rs/add-patch-quit'

The 'q'(uit) command in "git add -p" has been improved to quit
without doing any meaningless work before leaving, and giving EOF
(typically control-D) to the prompt is made to behave the same way.

* rs/add-patch-quit:
  add-patch: quit on EOF
  add-patch: quit without skipping undecided hunks
This commit is contained in:
Junio C Hamano
2025-11-03 06:49:54 -08:00
2 changed files with 18 additions and 6 deletions

View 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;
@@ -1601,7 +1603,7 @@ soft_increment:
} else if (hunk->use == UNDECIDED_HUNK) {
hunk->use = USE_HUNK;
}
} else if (ch == 'd' || ch == 'q') {
} else if (ch == 'd') {
if (file_diff->hunk_nr) {
for (; hunk_index < file_diff->hunk_nr; hunk_index++) {
hunk = file_diff->hunk + hunk_index;
@@ -1613,10 +1615,9 @@ soft_increment:
} else if (hunk->use == UNDECIDED_HUNK) {
hunk->use = SKIP_HUNK;
}
if (ch == 'q') {
quit = 1;
break;
}
} else if (ch == 'q') {
quit = 1;
break;
} else if (s->answer.buf[0] == 'K') {
if (permitted & ALLOW_GOTO_PREVIOUS_HUNK)
hunk_index = dec_mod(hunk_index,

View File

@@ -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