Skip to content

Commit 694e517

Browse files
committed
Merge branch 'jk/add-i-fixes'
"add -i/-p" fixes. * jk/add-i-fixes: add--interactive.perl: specify --no-color explicitly add-patch: fix inverted return code of repo_read_index()
2 parents 3ad8d3e + 1c6ffb5 commit 694e517

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

add-patch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,7 @@ static int patch_update_file(struct add_p_state *s,
16551655
NULL, 0, NULL, 0))
16561656
error(_("'git apply' failed"));
16571657
}
1658-
if (!repo_read_index(s->s.r))
1658+
if (repo_read_index(s->s.r) >= 0)
16591659
repo_refresh_and_write_index(s->s.r, REFRESH_QUIET, 0,
16601660
1, NULL, NULL, NULL);
16611661
}

git-add--interactive.perl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ sub parse_diff {
714714
if (defined $patch_mode_revision) {
715715
push @diff_cmd, get_diff_reference($patch_mode_revision);
716716
}
717-
my @diff = run_cmd_pipe("git", @diff_cmd, "--", $path);
717+
my @diff = run_cmd_pipe("git", @diff_cmd, qw(--no-color --), $path);
718718
my @colored = ();
719719
if ($diff_use_color) {
720720
my @display_cmd = ("git", @diff_cmd, qw(--color --), $path);

t/t3701-add-interactive.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,12 +569,20 @@ test_expect_success 'patch mode ignores unmerged entries' '
569569
diff_cmp expected diff
570570
'
571571

572+
test_expect_success 'index is refreshed after applying patch' '
573+
git reset --hard &&
574+
echo content >test &&
575+
printf y | git add -p &&
576+
git diff-files --exit-code
577+
'
578+
572579
test_expect_success 'diffs can be colorized' '
573580
git reset --hard &&
574581
575582
echo content >test &&
576583
printf y >y &&
577584
force_color git add -p >output 2>&1 <y &&
585+
git diff-files --exit-code &&
578586
579587
# We do not want to depend on the exact coloring scheme
580588
# git uses for diffs, so just check that we saw some kind of color.

0 commit comments

Comments
 (0)