Skip to content

Commit

Permalink
built-in add -i: accept open-ended ranges again
Browse files Browse the repository at this point in the history
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 <johannes.schindelin@gmx.de>
  • Loading branch information
dscho authored and Git for Windows Build Agent committed Jan 16, 2020
1 parent fad660b commit 16fed22
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion add-interactive.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,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;
Expand Down
9 changes: 9 additions & 0 deletions t/t3701-add-interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,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 &&
Expand Down

0 comments on commit 16fed22

Please sign in to comment.