1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-06-19 12:29:06 +02:00

add-interactive: fix deletion of non-empty files

Commit 24ab81a fixed the deletion of empty files, but broke
deletion of non-empty files. The approach it took was to
factor out the "deleted" line from the patch header into its
own hunk, the same way we do for mode changes. However,
unlike mode changes, we only showed the special "delete this
file" hunk if there were no other hunks. Otherwise, the user
would annoyingly be presented with _two_ hunks: one for
deleting the file and one for deleting the content.

This meant that in the non-empty case, we forgot about the
deleted line entirely, and we submitted a bogus patch to
git-apply (with "/dev/null" as the destination file, but not
marked as a deletion).

Instead, this patch combines the file deletion hunk and the
content deletion hunk (if there is one) into a single
deletion hunk which is either staged or not.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King 2009-12-08 02:49:35 -05:00 committed by Junio C Hamano
parent 24ab81ae4d
commit 8947fdd598
2 changed files with 25 additions and 1 deletions

View File

@ -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);
}

View File

@ -214,6 +214,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