add-patch: fully document option P
Show option P in the prompt and explain it properly on a dedicated line in online help and documentation. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Oct 21, 2025 at 20:02 UTC
301e20da208d23e9ea03d58e1488973c6f1f939a
3 files changed
+26
-24
Documentation/git-add.adoc
+1
@@ -349,6 +349,7 @@ patch::
349
s - split the current hunk into smaller hunks
350
e - manually edit the current hunk
351
p - print the current hunk
352
+ P - print the current hunk using the pager
353
? - print help
354
+
355
After deciding the fate for all hunks, if there is any hunk
add-patch.c
+3
-2
@@ -1405,7 +1405,8 @@ N_("j - go to the next undecided hunk, roll over at the bottom\n"
1405
"/ - search for a hunk matching the given regex\n"
1406
"s - split the current hunk into smaller hunks\n"
1407
"e - manually edit the current hunk\n"
1408
- "p - print the current hunk, 'P' to use the pager\n"
1408
+ "p - print the current hunk\n"
1409
+ "P - print the current hunk using the pager\n"
1410
"? - print help\n");
1411
1412
static size_t dec_mod(size_t a, size_t m)
@@ -1536,7 +1537,7 @@ static int patch_update_file(struct add_p_state *s,
1537
permitted |= ALLOW_EDIT;
1538
strbuf_addstr(&s->buf, ",e");
1539
}
1539
- strbuf_addstr(&s->buf, ",p");
1540
+ strbuf_addstr(&s->buf, ",p,P");
1541
}
1542
if (file_diff->deleted)
1543
prompt_mode_type = PROMPT_DELETION;
t/t3701-add-interactive.sh
+22
-22
@@ -48,8 +48,8 @@ test_expect_success 'unknown command' '
48
git add -N command &&
49
git diff command >expect &&
50
cat >>expect <<-EOF &&
51
- (1/1) Stage addition [y,n,q,a,d,e,p,?]? Unknown command ${SQ}W${SQ} (use ${SQ}?${SQ} for help)
52
- (1/1) Stage addition [y,n,q,a,d,e,p,?]?$SP
51
+ (1/1) Stage addition [y,n,q,a,d,e,p,P,?]? Unknown command ${SQ}W${SQ} (use ${SQ}?${SQ} for help)
52
+ (1/1) Stage addition [y,n,q,a,d,e,p,P,?]?$SP
53
EOF
54
git add -p -- command <command >actual 2>&1 &&
55
test_cmp expect actual
@@ -332,9 +332,9 @@ test_expect_success 'different prompts for mode change/deleted' '
332
git -c core.filemode=true add -p >actual &&
333
sed -n "s/^\(([0-9/]*) Stage .*?\).*/\1/p" actual >actual.filtered &&
334
cat >expect <<-\EOF &&
335
- (1/1) Stage deletion [y,n,q,a,d,p,?]?
336
- (1/2) Stage mode change [y,n,q,a,d,k,K,j,J,g,/,p,?]?
337
- (2/2) Stage this hunk [y,n,q,a,d,K,J,g,/,e,p,?]?
335
+ (1/1) Stage deletion [y,n,q,a,d,p,P,?]?
336
+ (1/2) Stage mode change [y,n,q,a,d,k,K,j,J,g,/,p,P,?]?
337
+ (2/2) Stage this hunk [y,n,q,a,d,K,J,g,/,e,p,P,?]?
338
EOF
339
test_cmp expect actual.filtered
340
'
@@ -521,13 +521,13 @@ test_expect_success 'split hunk setup' '
521
test_expect_success 'goto hunk 1 with "g 1"' '
522
test_when_finished "git reset" &&
523
tr _ " " >expect <<-EOF &&
524
- (2/2) Stage this hunk [y,n,q,a,d,K,J,g,/,e,p,?]? + 1: -1,2 +1,3 +15
524
+ (2/2) Stage this hunk [y,n,q,a,d,K,J,g,/,e,p,P,?]? + 1: -1,2 +1,3 +15
525
_ 2: -2,4 +3,8 +21
526
go to which hunk? @@ -1,2 +1,3 @@
527
_10
528
+15
529
_20
530
- (1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,?]?_
530
+ (1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]?_
531
EOF
532
test_write_lines s y g 1 | git add -p >actual &&
533
tail -n 7 <actual >actual.trimmed &&
@@ -540,7 +540,7 @@ test_expect_success 'goto hunk 1 with "g1"' '
540
_10
541
+15
542
_20
543
- (1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,?]?_
543
+ (1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]?_
544
EOF
545
test_write_lines s y g1 | git add -p >actual &&
546
tail -n 4 <actual >actual.trimmed &&
@@ -550,11 +550,11 @@ test_expect_success 'goto hunk 1 with "g1"' '
550
test_expect_success 'navigate to hunk via regex /pattern' '
551
test_when_finished "git reset" &&
552
tr _ " " >expect <<-EOF &&
553
- (2/2) Stage this hunk [y,n,q,a,d,K,J,g,/,e,p,?]? @@ -1,2 +1,3 @@
553
+ (2/2) Stage this hunk [y,n,q,a,d,K,J,g,/,e,p,P,?]? @@ -1,2 +1,3 @@
554
_10
555
+15
556
_20
557
- (1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,?]?_
557
+ (1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]?_
558
EOF
559
test_write_lines s y /1,2 | git add -p >actual &&
560
tail -n 5 <actual >actual.trimmed &&
@@ -567,7 +567,7 @@ test_expect_success 'navigate to hunk via regex / pattern' '
567
_10
568
+15
569
_20
570
- (1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,?]?_
570
+ (1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]?_
571
EOF
572
test_write_lines s y / 1,2 | git add -p >actual &&
573
tail -n 4 <actual >actual.trimmed &&
@@ -579,11 +579,11 @@ test_expect_success 'print again the hunk' '
579
tr _ " " >expect <<-EOF &&
580
+15
581
20
582
- (1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,?]? @@ -1,2 +1,3 @@
582
+ (1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]? @@ -1,2 +1,3 @@
583
10
584
+15
585
20
586
- (1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,?]?_
586
+ (1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]?_
587
EOF
588
test_write_lines s y g 1 p | git add -p >actual &&
589
tail -n 7 <actual >actual.trimmed &&
@@ -595,11 +595,11 @@ test_expect_success TTY 'print again the hunk (PAGER)' '
595
cat >expect <<-EOF &&
596
<GREEN>+<RESET><GREEN>15<RESET>
597
20<RESET>
598
- <BOLD;BLUE>(1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,?]? <RESET>PAGER <CYAN>@@ -1,2 +1,3 @@<RESET>
598
+ <BOLD;BLUE>(1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]? <RESET>PAGER <CYAN>@@ -1,2 +1,3 @@<RESET>
599
PAGER 10<RESET>
600
PAGER <GREEN>+<RESET><GREEN>15<RESET>
601
PAGER 20<RESET>
602
- <BOLD;BLUE>(1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,?]? <RESET>
602
+ <BOLD;BLUE>(1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]? <RESET>
603
EOF
604
test_write_lines s y g 1 P |
605
(
@@ -796,21 +796,21 @@ test_expect_success 'colors can be overridden' '
796
<BLUE>+<RESET><BLUE>new<RESET>
797
<CYAN> more-context<RESET>
798
<BLUE>+<RESET><BLUE>another-one<RESET>
799
- <YELLOW>(1/1) Stage this hunk [y,n,q,a,d,s,e,p,?]? <RESET><BOLD>Split into 2 hunks.<RESET>
799
+ <YELLOW>(1/1) Stage this hunk [y,n,q,a,d,s,e,p,P,?]? <RESET><BOLD>Split into 2 hunks.<RESET>
800
<MAGENTA>@@ -1,3 +1,3 @@<RESET>
801
<CYAN> context<RESET>
802
<BOLD>-old<RESET>
803
<BLUE>+<RESET><BLUE>new<RESET>
804
<CYAN> more-context<RESET>
805
- <YELLOW>(1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,?]? <RESET><MAGENTA>@@ -3 +3,2 @@<RESET>
805
+ <YELLOW>(1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]? <RESET><MAGENTA>@@ -3 +3,2 @@<RESET>
806
<CYAN> more-context<RESET>
807
<BLUE>+<RESET><BLUE>another-one<RESET>
808
- <YELLOW>(2/2) Stage this hunk [y,n,q,a,d,K,J,g,/,e,p,?]? <RESET><MAGENTA>@@ -1,3 +1,3 @@<RESET>
808
+ <YELLOW>(2/2) Stage this hunk [y,n,q,a,d,K,J,g,/,e,p,P,?]? <RESET><MAGENTA>@@ -1,3 +1,3 @@<RESET>
809
<CYAN> context<RESET>
810
<BOLD>-old<RESET>
811
<BLUE>+new<RESET>
812
<CYAN> more-context<RESET>
813
- <YELLOW>(1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,?]? <RESET>
813
+ <YELLOW>(1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]? <RESET>
814
EOF
815
test_cmp expect actual
816
'
@@ -1393,9 +1393,9 @@ test_expect_success 'invalid option s is rejected' '
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,?]?
1396
+ (1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,s,e,p,P,?]?
1397
+ (2/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]? Sorry, cannot split this hunk
1398
+ (2/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]?
1399
EOF
1400
test_cmp expect actual
1401
'