]> git.ipfire.org Git - thirdparty/git.git/commitdiff
add-patch: document that option J rolls over
authorRené Scharfe <l.s.r@web.de>
Sun, 5 Oct 2025 15:55:24 +0000 (17:55 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sun, 5 Oct 2025 20:34:12 +0000 (13:34 -0700)
The variable "permitted" is only not reset after moving to a different
hunk, so it only accumulates permission and doesn't necessarily reflect
those of the current hunk.  This may be a bug, but is actually useful
with the option J, which can be used at the last hunk to roll over to
the first hunk.  Make this particular behavior official.

Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-add.adoc
add-patch.c
t/t3701-add-interactive.sh

index 3266ccf105f31e0a61afb04e78801656b6252944..5c05a3a7f9dffb1612d6c68e91929e92d015358b 100644 (file)
@@ -343,7 +343,7 @@ patch::
        g - select a hunk to go to
        / - search for a hunk matching the given regex
        j - go to the next undecided hunk
-       J - go to the next hunk
+       J - go to the next hunk, roll over at the bottom
        k - go to the previous undecided hunk
        K - go to the previous hunk
        s - split the current hunk into smaller hunks
index 912266a3f89a47a3f192c92865d8e19e3ef00a7f..bef2ba7a25271572e74cb2aec45b3badcf4c920c 100644 (file)
@@ -1398,7 +1398,7 @@ static size_t display_hunks(struct add_p_state *s,
 
 static const char help_patch_remainder[] =
 N_("j - go to the next undecided hunk\n"
-   "J - go to the next hunk\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"
    "g - select a hunk to go to\n"
@@ -1493,7 +1493,7 @@ static int patch_update_file(struct add_p_state *s,
                                permitted |= ALLOW_GOTO_NEXT_UNDECIDED_HUNK;
                                strbuf_addstr(&s->buf, ",j");
                        }
-                       if (hunk_index + 1 < file_diff->hunk_nr) {
+                       if (file_diff->hunk_nr > 1) {
                                permitted |= ALLOW_GOTO_NEXT_HUNK;
                                strbuf_addstr(&s->buf, ",J");
                        }
index d9fe289a7ad13a61aa92e3227678cad25ee2dc96..d5d2e120ab34ed4e486b32043e3d9452987a5e45 100755 (executable)
@@ -334,7 +334,7 @@ test_expect_success 'different prompts for mode change/deleted' '
        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,?]?
-       (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,p,?]?
+       (2/2) Stage this hunk [y,n,q,a,d,K,J,g,/,e,p,?]?
        EOF
        test_cmp expect actual.filtered
 '
@@ -521,7 +521,7 @@ test_expect_success 'split hunk setup' '
 test_expect_success 'goto hunk 1 with "g 1"' '
        test_when_finished "git reset" &&
        tr _ " " >expect <<-EOF &&
-       (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,p,?]? + 1:  -1,2 +1,3          +15
+       (2/2) Stage this hunk [y,n,q,a,d,K,J,g,/,e,p,?]? + 1:  -1,2 +1,3          +15
        _ 2:  -2,4 +3,8          +21
        go to which hunk? @@ -1,2 +1,3 @@
        _10
@@ -550,7 +550,7 @@ test_expect_success 'goto hunk 1 with "g1"' '
 test_expect_success 'navigate to hunk via regex /pattern' '
        test_when_finished "git reset" &&
        tr _ " " >expect <<-EOF &&
-       (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,p,?]? @@ -1,2 +1,3 @@
+       (2/2) Stage this hunk [y,n,q,a,d,K,J,g,/,e,p,?]? @@ -1,2 +1,3 @@
        _10
        +15
        _20
@@ -805,7 +805,7 @@ test_expect_success 'colors can be overridden' '
        <YELLOW>(1/2) Stage this hunk [y,n,q,a,d,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,g,/,e,p,?]? <RESET><MAGENTA>@@ -1,3 +1,3 @@<RESET>
+       <YELLOW>(2/2) Stage this hunk [y,n,q,a,d,K,J,g,/,e,p,?]? <RESET><MAGENTA>@@ -1,3 +1,3 @@<RESET>
        <CYAN> context<RESET>
        <BOLD>-old<RESET>
        <BLUE>+new<RESET>
@@ -1354,4 +1354,14 @@ do
        '
 done
 
+test_expect_success 'option J rolls 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 &&
+       sed -n -e "s-/.*--" -e "s/^(//p" <out >actual &&
+       test_cmp expect actual
+'
+
 test_done