Skip to content

Commit

Permalink
Merge branch 'jk/maint-add-p-delete-fix' into maint
Browse files Browse the repository at this point in the history
* jk/maint-add-p-delete-fix:
  add-interactive: fix deletion of non-empty files
  • Loading branch information
Junio C Hamano committed Dec 9, 2009
2 parents aa03131 + 8947fdd commit a876433
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion git-add--interactive.perl
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,11 @@ sub patch_update_file {
if (@{$mode->{TEXT}}) {
unshift @hunk, $mode;
}
if (@{$deletion->{TEXT}} && !@hunk) {
if (@{$deletion->{TEXT}}) {
foreach my $hunk (@hunk) {
push @{$deletion->{TEXT}}, @{$hunk->{TEXT}};
push @{$deletion->{DISPLAY}}, @{$hunk->{DISPLAY}};
}
@hunk = ($deletion);
}

Expand Down
20 changes: 20 additions & 0 deletions t/t3701-add-interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,26 @@ test_expect_success 'add first line works' '
test_cmp expected diff
'

cat >expected <<EOF
diff --git a/non-empty b/non-empty
deleted file mode 100644
index d95f3ad..0000000
--- a/non-empty
+++ /dev/null
@@ -1 +0,0 @@
-content
EOF
test_expect_success 'deleting a non-empty file' '
git reset --hard &&
echo content >non-empty &&
git add non-empty &&
git commit -m non-empty &&
rm non-empty &&
echo y | git add -p non-empty &&
git diff --cached >diff &&
test_cmp expected diff
'

cat >expected <<EOF
diff --git a/empty b/empty
deleted file mode 100644
Expand Down

0 comments on commit a876433

Please sign in to comment.