static const char help_patch_remainder[] =
N_("j - go to the next undecided hunk, roll over at the bottom\n"
"J - go to the next hunk, roll over at the bottom\n"
- "k - go to the previous undecided hunk\n"
- "K - go to the previous hunk\n"
+ "k - go to the previous undecided hunk, roll over at the top\n"
+ "K - go to the previous hunk, roll over at the top\n"
"g - select a hunk to go to\n"
"/ - search for a hunk matching the given regex\n"
"s - split the current hunk into smaller hunks\n"
"p - print the current hunk, 'P' to use the pager\n"
"? - print help\n");
+static size_t dec_mod(size_t a, size_t m)
+{
+ return a > 0 ? a - 1 : m - 1;
+}
+
static size_t inc_mod(size_t a, size_t m)
{
return a < m - 1 ? a + 1 : 0;
undecided_next = -1;
if (file_diff->hunk_nr) {
- for (i = hunk_index - 1; i >= 0; i--)
+ for (i = dec_mod(hunk_index, file_diff->hunk_nr);
+ i != hunk_index;
+ i = dec_mod(i, file_diff->hunk_nr))
if (file_diff->hunk[i].use == UNDECIDED_HUNK) {
undecided_previous = i;
break;
permitted |= ALLOW_GOTO_PREVIOUS_UNDECIDED_HUNK;
strbuf_addstr(&s->buf, ",k");
}
- if (hunk_index) {
+ if (file_diff->hunk_nr > 1) {
permitted |= ALLOW_GOTO_PREVIOUS_HUNK;
strbuf_addstr(&s->buf, ",K");
}
}
} else if (s->answer.buf[0] == 'K') {
if (permitted & ALLOW_GOTO_PREVIOUS_HUNK)
- hunk_index--;
+ hunk_index = dec_mod(hunk_index,
+ file_diff->hunk_nr);
else
- err(s, _("No previous hunk"));
+ err(s, _("No other hunk"));
} else if (s->answer.buf[0] == 'J') {
if (permitted & ALLOW_GOTO_NEXT_HUNK)
hunk_index++;
if (permitted & ALLOW_GOTO_PREVIOUS_UNDECIDED_HUNK)
hunk_index = undecided_previous;
else
- err(s, _("No previous hunk"));
+ err(s, _("No other undecided hunk"));
} else if (s->answer.buf[0] == 'j') {
if (permitted & ALLOW_GOTO_NEXT_UNDECIDED_HUNK)
hunk_index = undecided_next;
sed -n "s/^\(([0-9/]*) Stage .*?\).*/\1/p" actual >actual.filtered &&
cat >expect <<-\EOF &&
(1/1) Stage deletion [y,n,q,a,d,p,?]?
- (1/2) Stage mode change [y,n,q,a,d,j,J,g,/,p,?]?
+ (1/2) Stage mode change [y,n,q,a,d,k,K,j,J,g,/,p,?]?
(2/2) Stage this hunk [y,n,q,a,d,K,J,g,/,e,p,?]?
EOF
test_cmp expect actual.filtered
_10
+15
_20
- (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,?]?_
+ (1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,?]?_
EOF
test_write_lines s y g 1 | git add -p >actual &&
tail -n 7 <actual >actual.trimmed &&
_10
+15
_20
- (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,?]?_
+ (1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,?]?_
EOF
test_write_lines s y g1 | git add -p >actual &&
tail -n 4 <actual >actual.trimmed &&
_10
+15
_20
- (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,?]?_
+ (1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,?]?_
EOF
test_write_lines s y /1,2 | git add -p >actual &&
tail -n 5 <actual >actual.trimmed &&
_10
+15
_20
- (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,?]?_
+ (1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,?]?_
EOF
test_write_lines s y / 1,2 | git add -p >actual &&
tail -n 4 <actual >actual.trimmed &&
tr _ " " >expect <<-EOF &&
+15
20
- (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,?]? @@ -1,2 +1,3 @@
+ (1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,?]? @@ -1,2 +1,3 @@
10
+15
20
- (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,?]?_
+ (1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,?]?_
EOF
test_write_lines s y g 1 p | git add -p >actual &&
tail -n 7 <actual >actual.trimmed &&
cat >expect <<-EOF &&
<GREEN>+<RESET><GREEN>15<RESET>
20<RESET>
- <BOLD;BLUE>(1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,?]? <RESET>PAGER <CYAN>@@ -1,2 +1,3 @@<RESET>
+ <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>
PAGER 10<RESET>
PAGER <GREEN>+<RESET><GREEN>15<RESET>
PAGER 20<RESET>
- <BOLD;BLUE>(1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,?]? <RESET>
+ <BOLD;BLUE>(1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,?]? <RESET>
EOF
test_write_lines s y g 1 P |
(
<BOLD>-old<RESET>
<BLUE>+<RESET><BLUE>new<RESET>
<CYAN> more-context<RESET>
- <YELLOW>(1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,?]? <RESET><MAGENTA>@@ -3 +3,2 @@<RESET>
+ <YELLOW>(1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,?]? <RESET><MAGENTA>@@ -3 +3,2 @@<RESET>
<CYAN> more-context<RESET>
<BLUE>+<RESET><BLUE>another-one<RESET>
<YELLOW>(2/2) Stage this hunk [y,n,q,a,d,K,J,g,/,e,p,?]? <RESET><MAGENTA>@@ -1,3 +1,3 @@<RESET>
<BOLD>-old<RESET>
<BLUE>+new<RESET>
<CYAN> more-context<RESET>
- <YELLOW>(1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,?]? <RESET>
+ <YELLOW>(1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,?]? <RESET>
EOF
test_cmp expect actual
'
'
done
-test_expect_success 'option J rolls over' '
+test_expect_success 'options J, K roll over' '
test_write_lines a b c d e f g h i >file &&
git add file &&
test_write_lines X b c d e f g h X >file &&
- test_write_lines J J q | git add -p >out &&
- test_write_lines 1 2 1 >expect &&
+ test_write_lines J J K q | git add -p >out &&
+ test_write_lines 1 2 1 2 >expect &&
sed -n -e "s-/.*--" -e "s/^(//p" <out >actual &&
test_cmp expect actual
'
-test_expect_success 'options y, n, j, e roll over to next undecided (1)' '
+test_expect_success 'options y, n, j, k, e roll over to next undecided (1)' '
test_write_lines a b c d e f g h i j k l m n o p q >file &&
git add file &&
test_write_lines X b c d e f g h X j k l m n o p X >file &&
test_set_editor : &&
- test_write_lines g3 y g3 n g3 j g3 e q | git add -p >out &&
- test_write_lines 1 3 1 3 1 3 1 3 1 >expect &&
+ test_write_lines g3 y g3 n g3 j g3 e k q | git add -p >out &&
+ test_write_lines 1 3 1 3 1 3 1 3 1 2 >expect &&
sed -n -e "s-/.*--" -e "s/^(//p" <out >actual &&
test_cmp expect actual
'
-test_expect_success 'options y, n, j, e roll over to next undecided (2)' '
+test_expect_success 'options y, n, j, k, e roll over to next undecided (2)' '
test_write_lines a b c d e f g h i j k l m n o p q >file &&
git add file &&
test_write_lines X b c d e f g h X j k l m n o p X >file &&
test_set_editor : &&
- test_write_lines y g3 y g3 n g3 j g3 e q | git add -p >out &&
- test_write_lines 1 2 3 2 3 2 3 2 3 2 >expect &&
+ test_write_lines y g3 y g3 n g3 j g3 e g1 k q | git add -p >out &&
+ test_write_lines 1 2 3 2 3 2 3 2 3 2 1 2 >expect &&
sed -n -e "s-/.*--" -e "s/^(//p" <out >actual &&
test_cmp expect actual
'