Skip to content

Two fixes for the built-in git add -i #2472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions 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 Expand Up @@ -931,7 +934,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 };

Expand Down Expand Up @@ -972,7 +975,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",
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