diff options
author | Andreas Gruenbacher <agruen@suse.de> | 2010-05-03 21:58:40 +0200 |
---|---|---|
committer | Andreas Gruenbacher <agruen@suse.de> | 2010-05-03 21:58:40 +0200 |
commit | a93dea1dce7a626cd3d6e4663988efd0b1be6864 (patch) | |
tree | 5b54b6dbaf2be7f806d78563d232fc2181901817 | |
parent | 76aa1070c87e463ae4ea781dd5e0b1709c577d04 (diff) | |
download | patch-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-- | ChangeLog | 4 | ||||
-rw-r--r-- | src/pch.c | 7 | ||||
-rw-r--r-- | tests/create-delete | 30 |
3 files changed, 38 insertions, 3 deletions
@@ -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 @@ -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 |