开发者

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

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 t开发者_如何学运维o 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!


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.


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


Edited: So we established that patch is not an SVN tool. SVN doesn't have any direct influence on this, unless it created the patch file incorrectly.

Are you sure the patchfile was created from the trunk? If so, your copy should be identical to the one that the patch was based on, so there should be no reason for it to fail. The only conclusion I can think of is that there is something wrong with the patch file; it does not match your file.

Confirm that dir/file.xml in your working copy really contains

  <markup>
  <markup />
  <markup>
  <markup>

starting at line 7. (I'm assuming the code in your question is just an edited copy anyway, because there should be 7 lines there, not 4.) That is, does the content of the file match the content of the patch? Pay particular attention to spacing and line endings. If it does, then there should be no reason why patch would fail that hunk.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜