Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is patch rejecting my patch-file on a SVN working copy?

Tags:

svn

patch

I have a patchfile like this:

Index: dir/file.xml
===================================================================
--- dir/file.xml    (revision 178)
+++ dir/file.xml    (working copy)
@@ -7,7 +7,7 @@
    <markup>
-   <markup />
+   <markup></markup>
    <markup>
    <markup>
@@ -20,6 +20,7 @@
    <markup>
    <markup>
+   <tag>
    <markup>

To apply it to the SVN working copy, I branched it using:

$ svn copy -r 178 trunk/component/dir branches/mybranch

Then I tried

$ cd branches/mybranch
$ ls -R
./dir:
file.xml
$ patch -p0 -i ~/patchfile.patch

but SVN's output is

(Stripping trailing CRs from patch.)
patching file dir/file.xml
Hunk #1 FAILED at 7.
Hunk #2 FAILED at 20.
2 out of 2 hunks FAILED -- saving rejects to file dir/file.xml.rej

for every file?

What could cause SVN to reject the patch? I am on a UNIX machine but patch and repository have Windows line-endings...

Thanks for help!

like image 450
Simon Avatar asked Jan 14 '11 14:01

Simon


2 Answers

The dos2unix tip was not bad but did not solve the problem as suggested.

What I did to actually patch all the files:

$ cd branches/mybranch
$ sudo apt-get install tofrodos
$ fromdos ~/patchfile.patch
$ fromdos */*
$ patch -p0 -i ~/patchfile.patch
$ todos */*

So basically patch seems to have a problem handling CR/LF lines under Unix. Converting it to LF, then patch and convert it back after patching helped.

Credits to Stefan.

like image 153
Simon Avatar answered Oct 16 '22 13:10

Simon


you could try the dos2unix tool on the patch file. That will convert the line endings.

like image 31
Stefan Avatar answered Oct 16 '22 12:10

Stefan