]> git.ipfire.org Git - thirdparty/git.git/commitdiff
built-in add -i: accept open-ended ranges again
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Thu, 16 Jan 2020 08:33:07 +0000 (08:33 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 16 Jan 2020 22:10:23 +0000 (14:10 -0800)
The interactive `add` command allows selecting multiple files for some
of its sub-commands, via unique prefixes, indices or index ranges.

When re-implementing `git add -i` in C, we even added a code comment
talking about ranges with a missing end index, such as `2-`, but the
code did not actually accept those, as pointed out in
https://github.com/git-for-windows/git/issues/2466#issuecomment-574142760.

Let's fix this, and add a test case to verify that this stays fixed
forever.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
add-interactive.c
t/t3701-add-interactive.sh

index 14d4688c26804624eb1ad77689d0d28742088821..396066e7246da7ddb0284f1f953104cfc04a593d 100644 (file)
@@ -328,7 +328,10 @@ static ssize_t list_and_choose(struct add_i_state *s,
                                if (endp == p + sep)
                                        to = from + 1;
                                else if (*endp == '-') {
-                                       to = strtoul(++endp, &endp, 10);
+                                       if (isdigit(*(++endp)))
+                                               to = strtoul(endp, &endp, 10);
+                                       else
+                                               to = items->items.nr;
                                        /* extra characters after the range? */
                                        if (endp != p + sep)
                                                from = -1;
index d4f9386621b468ae805febf7382268ed8bf53d8d..b02fe73631dc9e56827caa7a90e2b38ba4eb7c4c 100755 (executable)
@@ -57,6 +57,15 @@ test_expect_success 'revert works (initial)' '
        ! grep . output
 '
 
+test_expect_success 'add untracked (multiple)' '
+       test_when_finished "git reset && rm [1-9]" &&
+       touch $(test_seq 9) &&
+       test_write_lines a "2-5 8-" | git add -i -- [1-9] &&
+       test_write_lines 2 3 4 5 8 9 >expected &&
+       git ls-files [1-9] >output &&
+       test_cmp expected output
+'
+
 test_expect_success 'setup (commit)' '
        echo baseline >file &&
        git add file &&