summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gruenbacher <agruen@linbit.com>2012-09-25 02:56:56 +0200
committerAndreas Gruenbacher <agruen@linbit.com>2012-09-25 04:07:53 +0200
commit1d9ed51e9c812d49affc2f9b3cd985257f6a525b (patch)
tree0a3669f851722f909dfd705ad006745828e7b9c8
parentb272c2d535c3d9d6ff30ec83b5fa6e97aa3545f1 (diff)
downloadpatch-1d9ed51e9c812d49affc2f9b3cd985257f6a525b.tar.gz
Only expect files to become empty if the patch says so
Test cases based on patches from Dmitry V. Levin <ldv@altlinux.org>. * src/patch.c (main): Only expect files to become empty if the patch says so. * NEWS: Document this change. * tests/create-delete: Add (more) empty vs. non-empty test cases.
-rw-r--r--NEWS2
-rw-r--r--src/patch.c2
-rw-r--r--tests/create-delete80
3 files changed, 73 insertions, 11 deletions
diff --git a/NEWS b/NEWS
index 23bc07c..434f21c 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,6 @@
* Two critical bug fixes in the "diff --git" format support.
+* Only expect files to become empty if the patch says so (the "other" file
+ must be /dev/null or dated the Epoch).
* Various improvements to messages when applying a patch to a file of different
type (regular file vs. symlink), when there are line ending differences (LF
vs. CRLF), and when in --dry-run mode.
diff --git a/src/patch.c b/src/patch.c
index f05e542..7ca7564 100644
--- a/src/patch.c
+++ b/src/patch.c
@@ -512,7 +512,7 @@ main (int argc, char **argv)
else
{
if (! outstate.zero_output
- && pch_says_nonexistent (! reverse)
+ && pch_says_nonexistent (! reverse) == 2
&& ! (merge && somefailed))
{
mismatch = true;
diff --git a/tests/create-delete b/tests/create-delete
index 7eed11f..54dd920 100644
--- a/tests/create-delete
+++ b/tests/create-delete
@@ -168,33 +168,93 @@ EOF
check 'cat f' <<EOF
f
EOF
-#
-# ----------------------------------------------------------------
-# This test deletes the target file.
+# ================================================================
+# File expected to become empty doesn't become empty
-echo data > target
+seq 2 > target
cat > p.diff <<EOF
-diff --git a/target b/target
-deleted file mode 100644
-index 1269488..0000000
+--- target
++++ /dev/null
+@@ -1 +0,0 @@
+-1
EOF
-check 'patch -p1 -b < p.diff || echo status: $?' <<EOF
+check 'patch -p0 -b < p.diff || echo status: $?' <<EOF
patching file target
File target is not empty after patch, as expected
status: 1
EOF
check 'cat target' <<EOF
-data
+2
EOF
# Patch creates a backup file even when the original file remains unchanged:
check 'cat target.orig' <<EOF
-data
+1
+2
+EOF
+
+# --------------------------------------------------------------
+
+seq 2 > target
+cat > p.diff <<EOF
+--- target 2012-09-25 03:09:15
++++ target 1970-01-01 00:00:00
+@@ -1 +0,0 @@
+-1
+EOF
+
+check 'patch -p0 < p.diff || echo status: $?' <<EOF
+patching file target
+File target is not empty after patch, as expected
+status: 1
+EOF
+
+check 'cat target' <<EOF
+2
+EOF
+
+# --------------------------------------------------------------
+printf '\0' > target
+cat > p.diff <<EOF
+diff --git a/target b/target
+deleted file mode 100644
+index f76dd23..0000000
+Binary files a/target and /dev/null differ
+EOF
+
+check 'patch -p1 < p.diff || echo status: $?' <<EOF
+patching file target
+File target is not empty after patch, as expected
+status: 1
+EOF
+
+ncheck 'test -e target'
+
+# ================================================================
+# File not expected to become empty does become empty
+
+echo 1 > target
+cat > p.diff <<EOF
+--- target
++++ target
+@@ -1 +0,0 @@
+-1
+EOF
+
+check 'patch -p0 < p.diff || echo status: $?' <<EOF
+patching file target
+EOF
+
+check 'cat target' <<EOF
EOF
+# ================================================================
+# File expected to become empty does become empty
+
+echo data > target
cat > p.diff <<EOF
diff --git a/target b/target
deleted file mode 100644