summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gruenbacher <agruen@suse.de>2010-05-03 21:58:40 +0200
committerAndreas Gruenbacher <agruen@suse.de>2010-05-03 21:58:40 +0200
commita93dea1dce7a626cd3d6e4663988efd0b1be6864 (patch)
tree5b54b6dbaf2be7f806d78563d232fc2181901817
parent76aa1070c87e463ae4ea781dd5e0b1709c577d04 (diff)
downloadpatch-a93dea1dce7a626cd3d6e4663988efd0b1be6864.tar.gz
Stick to the best name in the reversed-patch check
* src/pch.c (intuit_diff_type): Fix a bug where the reversed-patch check would wrongly pick the last name instead of the best name. * src/create-delete: Add test cases for that.
-rw-r--r--ChangeLog4
-rw-r--r--src/pch.c7
-rw-r--r--tests/create-delete30
3 files changed, 38 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 7df3427..740ff79 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2009-05-02 Andreas Gruenbacher <agruen@suse.de>
+ * src/pch.c (intuit_diff_type): Fix a bug where the reversed-patch
+ check would wrongly pick the last name instead of the best name.
+ * src/create-delete: Add test cases for that.
+
* src/pch.c (fetchmode): Document that the "diff --git" format does
not store file permissions of symlinks.
* src/util.c (set_file_attributes): Since we don't have symlink file
diff --git a/src/pch.c b/src/pch.c
index db50892..74e010c 100644
--- a/src/pch.c
+++ b/src/pch.c
@@ -843,9 +843,10 @@ intuit_diff_type (bool need_header, mode_t *p_file_type)
if (i0 != NONE
&& (i == NONE || (st[i].st_mode & S_IFMT) == file_type)
- && maybe_reverse (p_name[i0], i == NONE,
- i == NONE || st[i].st_size == 0))
- i = i0;
+ && maybe_reverse (p_name[i == NONE ? i0 : i], i == NONE,
+ i == NONE || st[i].st_size == 0)
+ && i == NONE)
+ i = i0;
if (i == NONE && p_says_nonexistent[reverse])
{
diff --git a/tests/create-delete b/tests/create-delete
index c71de21..5b3d9c8 100644
--- a/tests/create-delete
+++ b/tests/create-delete
@@ -113,3 +113,33 @@ Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file f.rej
Status: 1
EOF
+
+# ==============================================================
+
+: > f.orig
+echo f > f
+diff -u f f.orig > f.diff
+mv f.orig f
+check 'patch -p0 -t < f.diff || echo "Status: $?"' <<EOF
+The next patch would empty out the file f,
+which is already empty! Assuming -R.
+patching file f
+EOF
+
+check 'cat f' <<EOF
+f
+EOF
+
+: > f.orig
+echo f > f
+diff -u f /dev/null > f.diff
+mv f.orig f
+check 'patch -p0 -t < f.diff || echo "Status: $?"' <<EOF
+The next patch would empty out the file f,
+which is already empty! Assuming -R.
+patching file f
+EOF
+
+check 'cat f' <<EOF
+f
+EOF