Skip to content

Commit 208e23e

Browse files
rscharfegitster
authored andcommitted
add-patch: reset "permitted" at loop start
Don't accumulate allowed options from any visited hunks, start fresh at the top of the loop instead and only record the allowed options for the current hunk. Reported-by: Junio C Hamano <[email protected]> Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e8c744d commit 208e23e

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

add-patch.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,15 +1439,6 @@ static int patch_update_file(struct add_p_state *s,
14391439
struct child_process cp = CHILD_PROCESS_INIT;
14401440
int colored = !!s->colored.len, quit = 0, use_pager = 0;
14411441
enum prompt_mode_type prompt_mode_type;
1442-
enum {
1443-
ALLOW_GOTO_PREVIOUS_HUNK = 1 << 0,
1444-
ALLOW_GOTO_PREVIOUS_UNDECIDED_HUNK = 1 << 1,
1445-
ALLOW_GOTO_NEXT_HUNK = 1 << 2,
1446-
ALLOW_GOTO_NEXT_UNDECIDED_HUNK = 1 << 3,
1447-
ALLOW_SEARCH_AND_GOTO = 1 << 4,
1448-
ALLOW_SPLIT = 1 << 5,
1449-
ALLOW_EDIT = 1 << 6
1450-
} permitted = 0;
14511442

14521443
/* Empty added files have no hunks */
14531444
if (!file_diff->hunk_nr && !file_diff->added)
@@ -1457,6 +1448,16 @@ static int patch_update_file(struct add_p_state *s,
14571448
render_diff_header(s, file_diff, colored, &s->buf);
14581449
fputs(s->buf.buf, stdout);
14591450
for (;;) {
1451+
enum {
1452+
ALLOW_GOTO_PREVIOUS_HUNK = 1 << 0,
1453+
ALLOW_GOTO_PREVIOUS_UNDECIDED_HUNK = 1 << 1,
1454+
ALLOW_GOTO_NEXT_HUNK = 1 << 2,
1455+
ALLOW_GOTO_NEXT_UNDECIDED_HUNK = 1 << 3,
1456+
ALLOW_SEARCH_AND_GOTO = 1 << 4,
1457+
ALLOW_SPLIT = 1 << 5,
1458+
ALLOW_EDIT = 1 << 6
1459+
} permitted = 0;
1460+
14601461
if (hunk_index >= file_diff->hunk_nr)
14611462
hunk_index = 0;
14621463
hunk = file_diff->hunk_nr

t/t3701-add-interactive.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,4 +1386,18 @@ test_expect_success 'options y, n, a, d, j, k, e roll over to next undecided (2)
13861386
test_cmp expect actual
13871387
'
13881388

1389+
test_expect_success 'invalid option s is rejected' '
1390+
test_write_lines a b c d e f g h i j k >file &&
1391+
git add file &&
1392+
test_write_lines X b X d e f g h i j X >file &&
1393+
test_write_lines j s q | git add -p >out &&
1394+
sed -ne "s/ @@.*//" -e "s/ \$//" -e "/^(/p" <out >actual &&
1395+
cat >expect <<-EOF &&
1396+
(1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,s,e,p,?]?
1397+
(2/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,?]? Sorry, cannot split this hunk
1398+
(2/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,?]?
1399+
EOF
1400+
test_cmp expect actual
1401+
'
1402+
13891403
test_done

0 commit comments

Comments
 (0)