Skip to content

Commit 15d73b6

Browse files
dschoGit for Windows Build Agent
authored andcommitted
Merge pull request #2472 from dscho/builtin-add-i-fixes
Two fixes for the built-in `git add -i`
2 parents ca9dab9 + 53a09af commit 15d73b6

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

add-interactive.c

Lines changed: 6 additions & 3 deletions
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;
@@ -931,7 +934,7 @@ static int run_patch(struct add_i_state *s, const struct pathspec *ps,
931934

932935
opts->prompt = N_("Patch update");
933936
count = list_and_choose(s, files, opts);
934-
if (count >= 0) {
937+
if (count > 0) {
935938
struct argv_array args = ARGV_ARRAY_INIT;
936939
struct pathspec ps_selected = { 0 };
937940

@@ -972,7 +975,7 @@ static int run_diff(struct add_i_state *s, const struct pathspec *ps,
972975
opts->flags = IMMEDIATE;
973976
count = list_and_choose(s, files, opts);
974977
opts->flags = 0;
975-
if (count >= 0) {
978+
if (count > 0) {
976979
struct argv_array args = ARGV_ARRAY_INIT;
977980

978981
argv_array_pushl(&args, "git", "diff", "-p", "--cached",

t/t3701-add-interactive.sh

Lines changed: 9 additions & 0 deletions
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)