@matheusbsbs / matheus-bagliano / commits / 849e43cc18
Fork 0

built-in add -i: accept open-ended ranges again

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>

Johannes Schindelin committed Jan 16, 2020 at 08:33 UTC 849e43cc18a8aef639b92c5df9b66af3eb983b2a
2 files changed +13 -1
add-interactive.c
+4 -1
@@ -328,7 +328,10 @@ static ssize_t list_and_choose(struct add_i_state *s,
328 if (endp == p + sep)
329 to = from + 1;
330 else if (*endp == '-') {
331 - to = strtoul(++endp, &endp, 10);
331 + if (isdigit(*(++endp)))
332 + to = strtoul(endp, &endp, 10);
333 + else
334 + to = items->items.nr;
335 /* extra characters after the range? */
336 if (endp != p + sep)
337 from = -1;
t/t3701-add-interactive.sh
+9
@@ -57,6 +57,15 @@ test_expect_success 'revert works (initial)' '
57 ! grep . output
58 '
59
60 +test_expect_success 'add untracked (multiple)' '
61 + test_when_finished "git reset && rm [1-9]" &&
62 + touch $(test_seq 9) &&
63 + test_write_lines a "2-5 8-" | git add -i -- [1-9] &&
64 + test_write_lines 2 3 4 5 8 9 >expected &&
65 + git ls-files [1-9] >output &&
66 + test_cmp expected output
67 +'
68 +
69 test_expect_success 'setup (commit)' '
70 echo baseline >file &&
71 git add file &&