Skip to content

Commit

Permalink
Merge branch 'jk/add-i-fixes'
Browse files Browse the repository at this point in the history
"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()
  • Loading branch information
gitster committed Sep 19, 2020
2 parents 3ad8d3e + 1c6ffb5 commit 694e517
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion add-patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -1655,7 +1655,7 @@ static int patch_update_file(struct add_p_state *s,
NULL, 0, NULL, 0))
error(_("'git apply' failed"));
}
if (!repo_read_index(s->s.r))
if (repo_read_index(s->s.r) >= 0)
repo_refresh_and_write_index(s->s.r, REFRESH_QUIET, 0,
1, NULL, NULL, NULL);
}
Expand Down
2 changes: 1 addition & 1 deletion git-add--interactive.perl
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ sub parse_diff {
if (defined $patch_mode_revision) {
push @diff_cmd, get_diff_reference($patch_mode_revision);
}
my @diff = run_cmd_pipe("git", @diff_cmd, "--", $path);
my @diff = run_cmd_pipe("git", @diff_cmd, qw(--no-color --), $path);
my @colored = ();
if ($diff_use_color) {
my @display_cmd = ("git", @diff_cmd, qw(--color --), $path);
Expand Down
8 changes: 8 additions & 0 deletions t/t3701-add-interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -569,12 +569,20 @@ test_expect_success 'patch mode ignores unmerged entries' '
diff_cmp expected diff
'

test_expect_success 'index is refreshed after applying patch' '
git reset --hard &&
echo content >test &&
printf y | git add -p &&
git diff-files --exit-code
'

test_expect_success 'diffs can be colorized' '
git reset --hard &&
echo content >test &&
printf y >y &&
force_color git add -p >output 2>&1 <y &&
git diff-files --exit-code &&
# We do not want to depend on the exact coloring scheme
# git uses for diffs, so just check that we saw some kind of color.
Expand Down

0 comments on commit 694e517

Please sign in to comment.