Skip to content

Commit b1da993

Browse files
dschoGit for Windows Build Agent
authored and
Git for Windows Build Agent
committed
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 #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 08abeb5 commit b1da993

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
@@ -326,7 +326,10 @@ static ssize_t list_and_choose(struct add_i_state *s,
326326
if (endp == p + sep)
327327
to = from + 1;
328328
else if (*endp == '-') {
329-
to = strtoul(++endp, &endp, 10);
329+
if (isdigit(*(++endp)))
330+
to = strtoul(endp, &endp, 10);
331+
else
332+
to = items->items.nr;
330333
/* extra characters after the range? */
331334
if (endp != p + sep)
332335
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)