diff options
author | Johannes Schindelin <johannes.schindelin@gmx.de> | 2020-01-16 08:33:07 +0000 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2020-01-16 14:10:23 -0800 |
commit | 849e43cc18a8aef639b92c5df9b66af3eb983b2a (patch) | |
tree | e76e50354029b286d519c4e7a527a257b70c84aa | |
parent | built-in add -i: do not try to `patch`/`diff` an empty list of files (diff) | |
download | tgif-849e43cc18a8aef639b92c5df9b66af3eb983b2a.tar.xz |
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>
-rw-r--r-- | add-interactive.c | 5 | ||||
-rwxr-xr-x | t/t3701-add-interactive.sh | 9 |
2 files changed, 13 insertions, 1 deletions
diff --git a/add-interactive.c b/add-interactive.c index 14d4688c26..396066e724 100644 --- a/add-interactive.c +++ b/add-interactive.c @@ -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; diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index d4f9386621..b02fe73631 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -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 && |