Skip to content

Commit 18a7988

Browse files
committed
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
2 parents a99f379 + e56f6dc commit 18a7988

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

add-patch.c

Lines changed: 7 additions & 6 deletions
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;
@@ -1601,7 +1603,7 @@ static int patch_update_file(struct add_p_state *s,
16011603
} else if (hunk->use == UNDECIDED_HUNK) {
16021604
hunk->use = USE_HUNK;
16031605
}
1604-
} else if (ch == 'd' || ch == 'q') {
1606+
} else if (ch == 'd') {
16051607
if (file_diff->hunk_nr) {
16061608
for (; hunk_index < file_diff->hunk_nr; hunk_index++) {
16071609
hunk = file_diff->hunk + hunk_index;
@@ -1613,10 +1615,9 @@ static int patch_update_file(struct add_p_state *s,
16131615
} else if (hunk->use == UNDECIDED_HUNK) {
16141616
hunk->use = SKIP_HUNK;
16151617
}
1616-
if (ch == 'q') {
1617-
quit = 1;
1618-
break;
1619-
}
1618+
} else if (ch == 'q') {
1619+
quit = 1;
1620+
break;
16201621
} else if (s->answer.buf[0] == 'K') {
16211622
if (permitted & ALLOW_GOTO_PREVIOUS_HUNK)
16221623
hunk_index = dec_mod(hunk_index,

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)