Skip to content

Commit 4e2fe2b

Browse files
committed
Merge branch 'aa/add-p-previous-decisions' into next
"git add -p" and friends notes what the current status of the hunk being shown is. * aa/add-p-previous-decisions: add -p: show user's hunk decision when selecting hunks
2 parents a17b449 + 8cafc30 commit 4e2fe2b

File tree

2 files changed

+53
-46
lines changed

2 files changed

+53
-46
lines changed

add-patch.c

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ static struct patch_mode patch_mode_add = {
4242
.apply_args = { "--cached", NULL },
4343
.apply_check_args = { "--cached", NULL },
4444
.prompt_mode = {
45-
N_("Stage mode change [y,n,q,a,d%s,?]? "),
46-
N_("Stage deletion [y,n,q,a,d%s,?]? "),
47-
N_("Stage addition [y,n,q,a,d%s,?]? "),
48-
N_("Stage this hunk [y,n,q,a,d%s,?]? ")
45+
N_("Stage mode change%s [y,n,q,a,d%s,?]? "),
46+
N_("Stage deletion%s [y,n,q,a,d%s,?]? "),
47+
N_("Stage addition%s [y,n,q,a,d%s,?]? "),
48+
N_("Stage this hunk%s [y,n,q,a,d%s,?]? ")
4949
},
5050
.edit_hunk_hint = N_("If the patch applies cleanly, the edited hunk "
5151
"will immediately be marked for staging."),
@@ -64,10 +64,10 @@ static struct patch_mode patch_mode_stash = {
6464
.apply_args = { "--cached", NULL },
6565
.apply_check_args = { "--cached", NULL },
6666
.prompt_mode = {
67-
N_("Stash mode change [y,n,q,a,d%s,?]? "),
68-
N_("Stash deletion [y,n,q,a,d%s,?]? "),
69-
N_("Stash addition [y,n,q,a,d%s,?]? "),
70-
N_("Stash this hunk [y,n,q,a,d%s,?]? "),
67+
N_("Stash mode change%s [y,n,q,a,d%s,?]? "),
68+
N_("Stash deletion%s [y,n,q,a,d%s,?]? "),
69+
N_("Stash addition%s [y,n,q,a,d%s,?]? "),
70+
N_("Stash this hunk%s [y,n,q,a,d%s,?]? "),
7171
},
7272
.edit_hunk_hint = N_("If the patch applies cleanly, the edited hunk "
7373
"will immediately be marked for stashing."),
@@ -88,10 +88,10 @@ static struct patch_mode patch_mode_reset_head = {
8888
.is_reverse = 1,
8989
.index_only = 1,
9090
.prompt_mode = {
91-
N_("Unstage mode change [y,n,q,a,d%s,?]? "),
92-
N_("Unstage deletion [y,n,q,a,d%s,?]? "),
93-
N_("Unstage addition [y,n,q,a,d%s,?]? "),
94-
N_("Unstage this hunk [y,n,q,a,d%s,?]? "),
91+
N_("Unstage mode change%s [y,n,q,a,d%s,?]? "),
92+
N_("Unstage deletion%s [y,n,q,a,d%s,?]? "),
93+
N_("Unstage addition%s [y,n,q,a,d%s,?]? "),
94+
N_("Unstage this hunk%s [y,n,q,a,d%s,?]? "),
9595
},
9696
.edit_hunk_hint = N_("If the patch applies cleanly, the edited hunk "
9797
"will immediately be marked for unstaging."),
@@ -111,10 +111,10 @@ static struct patch_mode patch_mode_reset_nothead = {
111111
.apply_check_args = { "--cached", NULL },
112112
.index_only = 1,
113113
.prompt_mode = {
114-
N_("Apply mode change to index [y,n,q,a,d%s,?]? "),
115-
N_("Apply deletion to index [y,n,q,a,d%s,?]? "),
116-
N_("Apply addition to index [y,n,q,a,d%s,?]? "),
117-
N_("Apply this hunk to index [y,n,q,a,d%s,?]? "),
114+
N_("Apply mode change to index%s [y,n,q,a,d%s,?]? "),
115+
N_("Apply deletion to index%s [y,n,q,a,d%s,?]? "),
116+
N_("Apply addition to index%s [y,n,q,a,d%s,?]? "),
117+
N_("Apply this hunk to index%s [y,n,q,a,d%s,?]? "),
118118
},
119119
.edit_hunk_hint = N_("If the patch applies cleanly, the edited hunk "
120120
"will immediately be marked for applying."),
@@ -134,10 +134,10 @@ static struct patch_mode patch_mode_checkout_index = {
134134
.apply_check_args = { "-R", NULL },
135135
.is_reverse = 1,
136136
.prompt_mode = {
137-
N_("Discard mode change from worktree [y,n,q,a,d%s,?]? "),
138-
N_("Discard deletion from worktree [y,n,q,a,d%s,?]? "),
139-
N_("Discard addition from worktree [y,n,q,a,d%s,?]? "),
140-
N_("Discard this hunk from worktree [y,n,q,a,d%s,?]? "),
137+
N_("Discard mode change from worktree%s [y,n,q,a,d%s,?]? "),
138+
N_("Discard deletion from worktree%s [y,n,q,a,d%s,?]? "),
139+
N_("Discard addition from worktree%s [y,n,q,a,d%s,?]? "),
140+
N_("Discard this hunk from worktree%s [y,n,q,a,d%s,?]? "),
141141
},
142142
.edit_hunk_hint = N_("If the patch applies cleanly, the edited hunk "
143143
"will immediately be marked for discarding."),
@@ -157,10 +157,10 @@ static struct patch_mode patch_mode_checkout_head = {
157157
.apply_check_args = { "-R", NULL },
158158
.is_reverse = 1,
159159
.prompt_mode = {
160-
N_("Discard mode change from index and worktree [y,n,q,a,d%s,?]? "),
161-
N_("Discard deletion from index and worktree [y,n,q,a,d%s,?]? "),
162-
N_("Discard addition from index and worktree [y,n,q,a,d%s,?]? "),
163-
N_("Discard this hunk from index and worktree [y,n,q,a,d%s,?]? "),
160+
N_("Discard mode change from index and worktree%s [y,n,q,a,d%s,?]? "),
161+
N_("Discard deletion from index and worktree%s [y,n,q,a,d%s,?]? "),
162+
N_("Discard addition from index and worktree%s [y,n,q,a,d%s,?]? "),
163+
N_("Discard this hunk from index and worktree%s [y,n,q,a,d%s,?]? "),
164164
},
165165
.edit_hunk_hint = N_("If the patch applies cleanly, the edited hunk "
166166
"will immediately be marked for discarding."),
@@ -179,10 +179,10 @@ static struct patch_mode patch_mode_checkout_nothead = {
179179
.apply_for_checkout = 1,
180180
.apply_check_args = { NULL },
181181
.prompt_mode = {
182-
N_("Apply mode change to index and worktree [y,n,q,a,d%s,?]? "),
183-
N_("Apply deletion to index and worktree [y,n,q,a,d%s,?]? "),
184-
N_("Apply addition to index and worktree [y,n,q,a,d%s,?]? "),
185-
N_("Apply this hunk to index and worktree [y,n,q,a,d%s,?]? "),
182+
N_("Apply mode change to index and worktree%s [y,n,q,a,d%s,?]? "),
183+
N_("Apply deletion to index and worktree%s [y,n,q,a,d%s,?]? "),
184+
N_("Apply addition to index and worktree%s [y,n,q,a,d%s,?]? "),
185+
N_("Apply this hunk to index and worktree%s [y,n,q,a,d%s,?]? "),
186186
},
187187
.edit_hunk_hint = N_("If the patch applies cleanly, the edited hunk "
188188
"will immediately be marked for applying."),
@@ -202,10 +202,10 @@ static struct patch_mode patch_mode_worktree_head = {
202202
.apply_check_args = { "-R", NULL },
203203
.is_reverse = 1,
204204
.prompt_mode = {
205-
N_("Discard mode change from worktree [y,n,q,a,d%s,?]? "),
206-
N_("Discard deletion from worktree [y,n,q,a,d%s,?]? "),
207-
N_("Discard addition from worktree [y,n,q,a,d%s,?]? "),
208-
N_("Discard this hunk from worktree [y,n,q,a,d%s,?]? "),
205+
N_("Discard mode change from worktree%s [y,n,q,a,d%s,?]? "),
206+
N_("Discard deletion from worktree%s [y,n,q,a,d%s,?]? "),
207+
N_("Discard addition from worktree%s [y,n,q,a,d%s,?]? "),
208+
N_("Discard this hunk from worktree%s [y,n,q,a,d%s,?]? "),
209209
},
210210
.edit_hunk_hint = N_("If the patch applies cleanly, the edited hunk "
211211
"will immediately be marked for discarding."),
@@ -224,10 +224,10 @@ static struct patch_mode patch_mode_worktree_nothead = {
224224
.apply_args = { NULL },
225225
.apply_check_args = { NULL },
226226
.prompt_mode = {
227-
N_("Apply mode change to worktree [y,n,q,a,d%s,?]? "),
228-
N_("Apply deletion to worktree [y,n,q,a,d%s,?]? "),
229-
N_("Apply addition to worktree [y,n,q,a,d%s,?]? "),
230-
N_("Apply this hunk to worktree [y,n,q,a,d%s,?]? "),
227+
N_("Apply mode change to worktree%s [y,n,q,a,d%s,?]? "),
228+
N_("Apply deletion to worktree%s [y,n,q,a,d%s,?]? "),
229+
N_("Apply addition to worktree%s [y,n,q,a,d%s,?]? "),
230+
N_("Apply this hunk to worktree%s [y,n,q,a,d%s,?]? "),
231231
},
232232
.edit_hunk_hint = N_("If the patch applies cleanly, the edited hunk "
233233
"will immediately be marked for applying."),
@@ -1460,6 +1460,7 @@ static int patch_update_file(struct add_p_state *s,
14601460
render_diff_header(s, file_diff, colored, &s->buf);
14611461
fputs(s->buf.buf, stdout);
14621462
for (;;) {
1463+
const char *hunk_use_decision = "";
14631464
enum {
14641465
ALLOW_GOTO_PREVIOUS_HUNK = 1 << 0,
14651466
ALLOW_GOTO_PREVIOUS_UNDECIDED_HUNK = 1 << 1,
@@ -1564,8 +1565,14 @@ static int patch_update_file(struct add_p_state *s,
15641565
(uintmax_t)(file_diff->hunk_nr
15651566
? file_diff->hunk_nr
15661567
: 1));
1568+
if (hunk->use != UNDECIDED_HUNK) {
1569+
if (hunk->use == USE_HUNK)
1570+
hunk_use_decision = _(" (was: y)");
1571+
else
1572+
hunk_use_decision = _(" (was: n)");
1573+
}
15671574
printf(_(s->mode->prompt_mode[prompt_mode_type]),
1568-
s->buf.buf);
1575+
hunk_use_decision, s->buf.buf);
15691576
if (*s->s.reset_color_interactive)
15701577
fputs(s->s.reset_color_interactive, stdout);
15711578
fflush(stdout);

t/t3701-add-interactive.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ test_expect_success 'goto hunk 1 with "g 1"' '
527527
_10
528528
+15
529529
_20
530-
(1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]?_
530+
(1/2) Stage this hunk (was: y) [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]?_
531531
EOF
532532
test_write_lines s y g 1 | git add -p >actual &&
533533
tail -n 7 <actual >actual.trimmed &&
@@ -540,7 +540,7 @@ test_expect_success 'goto hunk 1 with "g1"' '
540540
_10
541541
+15
542542
_20
543-
(1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]?_
543+
(1/2) Stage this hunk (was: y) [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]?_
544544
EOF
545545
test_write_lines s y g1 | git add -p >actual &&
546546
tail -n 4 <actual >actual.trimmed &&
@@ -554,7 +554,7 @@ test_expect_success 'navigate to hunk via regex /pattern' '
554554
_10
555555
+15
556556
_20
557-
(1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]?_
557+
(1/2) Stage this hunk (was: y) [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]?_
558558
EOF
559559
test_write_lines s y /1,2 | git add -p >actual &&
560560
tail -n 5 <actual >actual.trimmed &&
@@ -567,7 +567,7 @@ test_expect_success 'navigate to hunk via regex / pattern' '
567567
_10
568568
+15
569569
_20
570-
(1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]?_
570+
(1/2) Stage this hunk (was: y) [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]?_
571571
EOF
572572
test_write_lines s y / 1,2 | git add -p >actual &&
573573
tail -n 4 <actual >actual.trimmed &&
@@ -579,11 +579,11 @@ test_expect_success 'print again the hunk' '
579579
tr _ " " >expect <<-EOF &&
580580
+15
581581
20
582-
(1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]? @@ -1,2 +1,3 @@
582+
(1/2) Stage this hunk (was: y) [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]? @@ -1,2 +1,3 @@
583583
10
584584
+15
585585
20
586-
(1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]?_
586+
(1/2) Stage this hunk (was: y) [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]?_
587587
EOF
588588
test_write_lines s y g 1 p | git add -p >actual &&
589589
tail -n 7 <actual >actual.trimmed &&
@@ -595,11 +595,11 @@ test_expect_success TTY 'print again the hunk (PAGER)' '
595595
cat >expect <<-EOF &&
596596
<GREEN>+<RESET><GREEN>15<RESET>
597597
20<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>
598+
<BOLD;BLUE>(1/2) Stage this hunk (was: y) [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]? <RESET>PAGER <CYAN>@@ -1,2 +1,3 @@<RESET>
599599
PAGER 10<RESET>
600600
PAGER <GREEN>+<RESET><GREEN>15<RESET>
601601
PAGER 20<RESET>
602-
<BOLD;BLUE>(1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]? <RESET>
602+
<BOLD;BLUE>(1/2) Stage this hunk (was: y) [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]? <RESET>
603603
EOF
604604
test_write_lines s y g 1 P |
605605
(
@@ -810,7 +810,7 @@ test_expect_success 'colors can be overridden' '
810810
<BOLD>-old<RESET>
811811
<BLUE>+new<RESET>
812812
<CYAN> more-context<RESET>
813-
<YELLOW>(1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]? <RESET>
813+
<YELLOW>(1/2) Stage this hunk (was: y) [y,n,q,a,d,k,K,j,J,g,/,e,p,P,?]? <RESET>
814814
EOF
815815
test_cmp expect actual
816816
'

0 commit comments

Comments
 (0)