Skip to content

Commit 2e76073

Browse files
dschojeffhostetler
authored andcommitted
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 git-for-windows#2466 (comment). Let's fix this, and add a test case to verify that this stays fixed forever. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent e208d20 commit 2e76073

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

add-interactive.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,10 @@ static ssize_t list_and_choose(struct add_i_state *s,
344344
if (endp == p + sep)
345345
to = from + 1;
346346
else if (*endp == '-') {
347-
to = strtoul(++endp, &endp, 10);
347+
if (isdigit(*(++endp)))
348+
to = strtoul(endp, &endp, 10);
349+
else
350+
to = items->items.nr;
348351
/* extra characters after the range? */
349352
if (endp != p + sep)
350353
from = -1;

t/t3701-add-interactive.sh

+9
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ test_expect_success 'revert works (initial)' '
6868
! grep . output
6969
'
7070

71+
test_expect_success 'add untracked (multiple)' '
72+
test_when_finished "git reset && rm [1-9]" &&
73+
touch $(test_seq 9) &&
74+
test_write_lines a "2-5 8-" | git add -i -- [1-9] &&
75+
test_write_lines 2 3 4 5 8 9 >expected &&
76+
git ls-files [1-9] >output &&
77+
test_cmp expected output
78+
'
79+
7180
test_expect_success 'setup (commit)' '
7281
echo baseline >file &&
7382
git add file &&

0 commit comments

Comments
 (0)