add-patch: introduce 'p' in interactive-patch
Shortly we're going make interactive-patch stop printing automatically the hunk under certain circumstances. Let's introduce a new option to allow the user to explicitly request the printing. Signed-off-by: Rubén Justo <rjusto@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Rubén Justo committed
Mar 29, 2024 at 04:58 UTC
66c14ab592f0226168a7411184c2e3ffc05e30b8
3 files changed
+16
-11
Documentation/git-add.txt
+1
@@ -348,6 +348,7 @@ patch::
348
K - leave this hunk undecided, see previous hunk
349
s - split the current hunk into smaller hunks
350
e - manually edit the current hunk
351
+ p - print the current hunk
352
? - print help
353
+
354
After deciding the fate for all hunks, if there is any hunk
add-patch.c
+4
@@ -1388,6 +1388,7 @@ N_("j - leave this hunk undecided, see next undecided hunk\n"
1388
"/ - search for a hunk matching the given regex\n"
1389
"s - split the current hunk into smaller hunks\n"
1390
"e - manually edit the current hunk\n"
1391
+ "p - print the current hunk\n"
1392
"? - print help\n");
1393
1394
static int patch_update_file(struct add_p_state *s,
@@ -1480,6 +1481,7 @@ static int patch_update_file(struct add_p_state *s,
1481
permitted |= ALLOW_EDIT;
1482
strbuf_addstr(&s->buf, ",e");
1483
}
1484
+ strbuf_addstr(&s->buf, ",p");
1485
}
1486
if (file_diff->deleted)
1487
prompt_mode_type = PROMPT_DELETION;
@@ -1658,6 +1660,8 @@ soft_increment:
1660
hunk->use = USE_HUNK;
1661
goto soft_increment;
1662
}
1663
+ } else if (s->answer.buf[0] == 'p') {
1664
+ /* nothing special is needed */
1665
} else {
1666
const char *p = _(help_patch_remainder), *eol = p;
1667
t/t3701-add-interactive.sh
+11
-11
@@ -325,9 +325,9 @@ test_expect_success 'different prompts for mode change/deleted' '
325
git -c core.filemode=true add -p >actual &&
326
sed -n "s/^\(([0-9/]*) Stage .*?\).*/\1/p" actual >actual.filtered &&
327
cat >expect <<-\EOF &&
328
- (1/1) Stage deletion [y,n,q,a,d,?]?
329
- (1/2) Stage mode change [y,n,q,a,d,j,J,g,/,?]?
330
- (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,?]?
328
+ (1/1) Stage deletion [y,n,q,a,d,p,?]?
329
+ (1/2) Stage mode change [y,n,q,a,d,j,J,g,/,p,?]?
330
+ (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,p,?]?
331
EOF
332
test_cmp expect actual.filtered
333
'
@@ -514,13 +514,13 @@ test_expect_success 'split hunk setup' '
514
test_expect_success 'goto hunk' '
515
test_when_finished "git reset" &&
516
tr _ " " >expect <<-EOF &&
517
- (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,?]? + 1: -1,2 +1,3 +15
517
+ (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,p,?]? + 1: -1,2 +1,3 +15
518
_ 2: -2,4 +3,8 +21
519
go to which hunk? @@ -1,2 +1,3 @@
520
_10
521
+15
522
_20
523
- (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]?_
523
+ (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,?]?_
524
EOF
525
test_write_lines s y g 1 | git add -p >actual &&
526
tail -n 7 <actual >actual.trimmed &&
@@ -530,11 +530,11 @@ test_expect_success 'goto hunk' '
530
test_expect_success 'navigate to hunk via regex' '
531
test_when_finished "git reset" &&
532
tr _ " " >expect <<-EOF &&
533
- (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,?]? @@ -1,2 +1,3 @@
533
+ (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,p,?]? @@ -1,2 +1,3 @@
534
_10
535
+15
536
_20
537
- (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]?_
537
+ (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,?]?_
538
EOF
539
test_write_lines s y /1,2 | git add -p >actual &&
540
tail -n 5 <actual >actual.trimmed &&
@@ -715,21 +715,21 @@ test_expect_success 'colors can be overridden' '
715
<BLUE>+<RESET><BLUE>new<RESET>
716
<CYAN> more-context<RESET>
717
<BLUE>+<RESET><BLUE>another-one<RESET>
718
- <YELLOW>(1/1) Stage this hunk [y,n,q,a,d,s,e,?]? <RESET><BOLD>Split into 2 hunks.<RESET>
718
+ <YELLOW>(1/1) Stage this hunk [y,n,q,a,d,s,e,p,?]? <RESET><BOLD>Split into 2 hunks.<RESET>
719
<MAGENTA>@@ -1,3 +1,3 @@<RESET>
720
<CYAN> context<RESET>
721
<BOLD>-old<RESET>
722
<BLUE>+<RESET><BLUE>new<RESET>
723
<CYAN> more-context<RESET>
724
- <YELLOW>(1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? <RESET><MAGENTA>@@ -3 +3,2 @@<RESET>
724
+ <YELLOW>(1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,?]? <RESET><MAGENTA>@@ -3 +3,2 @@<RESET>
725
<CYAN> more-context<RESET>
726
<BLUE>+<RESET><BLUE>another-one<RESET>
727
- <YELLOW>(2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,?]? <RESET><MAGENTA>@@ -1,3 +1,3 @@<RESET>
727
+ <YELLOW>(2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,p,?]? <RESET><MAGENTA>@@ -1,3 +1,3 @@<RESET>
728
<CYAN> context<RESET>
729
<BOLD>-old<RESET>
730
<BLUE>+new<RESET>
731
<CYAN> more-context<RESET>
732
- <YELLOW>(1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? <RESET>
732
+ <YELLOW>(1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,?]? <RESET>
733
EOF
734
test_cmp expect actual
735
'