Skip to content

Commit 66c14ab

Browse files
rjustogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c75fd8d commit 66c14ab

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

Documentation/git-add.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ patch::
348348
K - leave this hunk undecided, see previous hunk
349349
s - split the current hunk into smaller hunks
350350
e - manually edit the current hunk
351+
p - print the current hunk
351352
? - print help
352353
+
353354
After deciding the fate for all hunks, if there is any hunk

add-patch.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,7 @@ N_("j - leave this hunk undecided, see next undecided hunk\n"
13881388
"/ - search for a hunk matching the given regex\n"
13891389
"s - split the current hunk into smaller hunks\n"
13901390
"e - manually edit the current hunk\n"
1391+
"p - print the current hunk\n"
13911392
"? - print help\n");
13921393

13931394
static int patch_update_file(struct add_p_state *s,
@@ -1480,6 +1481,7 @@ static int patch_update_file(struct add_p_state *s,
14801481
permitted |= ALLOW_EDIT;
14811482
strbuf_addstr(&s->buf, ",e");
14821483
}
1484+
strbuf_addstr(&s->buf, ",p");
14831485
}
14841486
if (file_diff->deleted)
14851487
prompt_mode_type = PROMPT_DELETION;
@@ -1658,6 +1660,8 @@ static int patch_update_file(struct add_p_state *s,
16581660
hunk->use = USE_HUNK;
16591661
goto soft_increment;
16601662
}
1663+
} else if (s->answer.buf[0] == 'p') {
1664+
/* nothing special is needed */
16611665
} else {
16621666
const char *p = _(help_patch_remainder), *eol = p;
16631667

t/t3701-add-interactive.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,9 @@ test_expect_success 'different prompts for mode change/deleted' '
325325
git -c core.filemode=true add -p >actual &&
326326
sed -n "s/^\(([0-9/]*) Stage .*?\).*/\1/p" actual >actual.filtered &&
327327
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,?]?
331331
EOF
332332
test_cmp expect actual.filtered
333333
'
@@ -514,13 +514,13 @@ test_expect_success 'split hunk setup' '
514514
test_expect_success 'goto hunk' '
515515
test_when_finished "git reset" &&
516516
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
518518
_ 2: -2,4 +3,8 +21
519519
go to which hunk? @@ -1,2 +1,3 @@
520520
_10
521521
+15
522522
_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,?]?_
524524
EOF
525525
test_write_lines s y g 1 | git add -p >actual &&
526526
tail -n 7 <actual >actual.trimmed &&
@@ -530,11 +530,11 @@ test_expect_success 'goto hunk' '
530530
test_expect_success 'navigate to hunk via regex' '
531531
test_when_finished "git reset" &&
532532
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 @@
534534
_10
535535
+15
536536
_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,?]?_
538538
EOF
539539
test_write_lines s y /1,2 | git add -p >actual &&
540540
tail -n 5 <actual >actual.trimmed &&
@@ -715,21 +715,21 @@ test_expect_success 'colors can be overridden' '
715715
<BLUE>+<RESET><BLUE>new<RESET>
716716
<CYAN> more-context<RESET>
717717
<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>
719719
<MAGENTA>@@ -1,3 +1,3 @@<RESET>
720720
<CYAN> context<RESET>
721721
<BOLD>-old<RESET>
722722
<BLUE>+<RESET><BLUE>new<RESET>
723723
<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>
725725
<CYAN> more-context<RESET>
726726
<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>
728728
<CYAN> context<RESET>
729729
<BOLD>-old<RESET>
730730
<BLUE>+new<RESET>
731731
<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>
733733
EOF
734734
test_cmp expect actual
735735
'

0 commit comments

Comments
 (0)