Git fork

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 <gitster@pobox.com>
Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

René Scharfe and committed by
Junio C Hamano
208e23ea e8c744dd

+24 -9
+10 -9
add-patch.c
··· 1439 1439 struct child_process cp = CHILD_PROCESS_INIT; 1440 1440 int colored = !!s->colored.len, quit = 0, use_pager = 0; 1441 1441 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; 1451 1442 1452 1443 /* Empty added files have no hunks */ 1453 1444 if (!file_diff->hunk_nr && !file_diff->added) ··· 1457 1448 render_diff_header(s, file_diff, colored, &s->buf); 1458 1449 fputs(s->buf.buf, stdout); 1459 1450 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 + 1460 1461 if (hunk_index >= file_diff->hunk_nr) 1461 1462 hunk_index = 0; 1462 1463 hunk = file_diff->hunk_nr
+14
t/t3701-add-interactive.sh
··· 1386 1386 test_cmp expect actual 1387 1387 ' 1388 1388 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 + 1389 1403 test_done