Bug 138858 - patch(1) assumes that a file appears only once in the patch in check-only mode
Summary: patch(1) assumes that a file appears only once in the patch in check-only mode
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-09-15 21:40 UTC by deeptech71@gmail.com
Modified: 2018-01-03 05:16 UTC (History)
0 users

See Also:


Attachments
words.txt (43 bytes, text/plain; charset=US-ASCII)
2009-11-21 09:50 UTC, deeptech71@gmail.com
no flags Details
con.patch (453 bytes, patch)
2009-11-21 09:50 UTC, deeptech71@gmail.com
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description deeptech71@gmail.com 2009-09-15 21:40:03 UTC
There are patches that should be applied in a strict order to be successful (ie., on a set of files, apply patch#1 first, then apply patch#2 on the result yielded by applying patch#1). I concatenate the patches (in correct order), and pipe them to patch(1). But, as always, I check what would happen if the patches were applied (use the -C option). The test run can show wrong results if the concatenated patch references a file multiple times near a common line, probably because in the check-only mode, patch(1) tries to apply each hunk on the original, unmodified files.

Fix: 

(If this won't be fixed soon, it would be nice to have this documented in the manpages.)
How-To-Repeat: diff -u orig mod1 > mod1.patch # mod1 changes line N of orig
diff -u orig mod2 > mod2.patch # mod2 changes line N of orig, too !

cat mod1.patch mod2.patch | patch -Cs # looks OK
cat mod1.patch mod2.patch | patch -s # fail !
Comment 1 deeptech71@gmail.com 2009-11-21 09:50:15 UTC
let me be more concise:
put words.txt and con.patch in one directory, cd to that directory, then:

# cat con.patch | patch -p1 -Cs

the test run says that the patch looks OK (applies cleanly), so we
proceed with actual patching:

# cat con.patch | patch -p1 -C

but the patch actually fails, so the test run lied !
Comment 2 deeptech71@gmail.com 2011-09-01 05:50:36 UTC
i've just noticed that in my 2nd message i've screwed up the command
flags. restating everything:

put words.txt and con.patch in one directory, cd to that directory, and then do:
$ cat con.patch | patch -sp1 --check
the --check flag means "do not actually edit files, just check to see
what would happen". the above test run says that the patch applies
cleanly. now do:
$ cat con.patch | patch -sp1
notice that now the patch actually fails, so the test run lied.
Comment 3 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 07:58:32 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped