Skip to content

Commit f094074

Browse files
committed
Merge branch 'js/builtin-add-i-cmds'
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
2 parents 0afeb3f + 849e43c commit f094074

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

add-interactive.c

+6-3
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;
@@ -913,7 +916,7 @@ static int run_patch(struct add_i_state *s, const struct pathspec *ps,
913916

914917
opts->prompt = N_("Patch update");
915918
count = list_and_choose(s, files, opts);
916-
if (count >= 0) {
919+
if (count > 0) {
917920
struct argv_array args = ARGV_ARRAY_INIT;
918921
struct pathspec ps_selected = { 0 };
919922

@@ -954,7 +957,7 @@ static int run_diff(struct add_i_state *s, const struct pathspec *ps,
954957
opts->flags = IMMEDIATE;
955958
count = list_and_choose(s, files, opts);
956959
opts->flags = 0;
957-
if (count >= 0) {
960+
if (count > 0) {
958961
struct argv_array args = ARGV_ARRAY_INIT;
959962

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

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)