summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-03-17 22:02:20 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-03-17 22:02:20 (GMT)
commitf0c344ce578f71aeeee7d40cc01e66f74506ecf9 (patch)
tree9dceeebeff284e4ef6fa942c3b4271d03899a805
parentc522f061d551c9bb8684a7c3859b2ece4499b56b (diff)
parent849e43cc18a8aef639b92c5df9b66af3eb983b2a (diff)
downloadgit-f0c344ce578f71aeeee7d40cc01e66f74506ecf9.zip
git-f0c344ce578f71aeeee7d40cc01e66f74506ecf9.tar.gz
git-f0c344ce578f71aeeee7d40cc01e66f74506ecf9.tar.bz2
Merge branch 'js/builtin-add-i-cmds' into maint
Minor bugfixes to "git add -i" that has recently been rewritten in C. * js/builtin-add-i-cmds: built-in add -i: accept open-ended ranges again built-in add -i: do not try to `patch`/`diff` an empty list of files
-rw-r--r--add-interactive.c9
-rwxr-xr-xt/t3701-add-interactive.sh9
2 files changed, 15 insertions, 3 deletions
diff --git a/add-interactive.c b/add-interactive.c
index 6a5048c..143e694 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -326,7 +326,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;
@@ -913,7 +916,7 @@ static int run_patch(struct add_i_state *s, const struct pathspec *ps,
opts->prompt = N_("Patch update");
count = list_and_choose(s, files, opts);
- if (count >= 0) {
+ if (count > 0) {
struct argv_array args = ARGV_ARRAY_INIT;
struct pathspec ps_selected = { 0 };
@@ -954,7 +957,7 @@ static int run_diff(struct add_i_state *s, const struct pathspec *ps,
opts->flags = IMMEDIATE;
count = list_and_choose(s, files, opts);
opts->flags = 0;
- if (count >= 0) {
+ if (count > 0) {
struct argv_array args = ARGV_ARRAY_INIT;
argv_array_pushl(&args, "git", "diff", "-p", "--cached",
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index 12ee321..2182b1c 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -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 &&