5
  1. I have deleted some textual files using svn remove. But svn diff shows as removal of all content in the file. Applying a patch of that diff only modifies the content, does not remove the file.

  2. I renamed a directory which contains binary files using svn rename. A patch file from a normal svn diff does nothing.

How to make svn diff produce file that patch would apply, when svn cp or svn mv was used?

subversion diff including new files

Both the methods in above links does only modifications to the files. They do not get removed/renamed after applying a patch. Is it possible to get a working patch for the above changes?

5
  • Did you check-in the content on which you applied the patch? Sep 1, 2011 at 12:55
  • @JVerstry I don't quite understand your question. I did checkout a different copy of the svn repo and tried applying the patches to it, to test whether it works.
    – Nufail
    Sep 1, 2011 at 15:41
  • When you apply the patch, the information is only registered in hidden .svn files. However, a file will only be deleted AFTER you check-in the different copy of this svn repo. Sep 2, 2011 at 0:44
  • @JVerstry I used 'svn status' to check and compare after applying the patches. All the changes should be visible through it right?
    – Nufail
    Sep 2, 2011 at 5:04
  • I am struggling with the same problem. Quite frustrating.
    – muhuk
    Mar 5, 2012 at 5:52

3 Answers 3

5

From the patchman page:

-E or --remove-empty-files Remove output files that are empty after the patches have been applied. Normally this option is unnecessary, since patch can examine the time stamps on the header to deter‐ mine whether a file should exist after patching. However, if the input is not a context diff or if patch is conform‐ ing to POSIX, patch does not remove empty patched files unless this option is given. When patch removes a file, it also attempts to remove any empty ancestor directories.

1

Try this:

patch -p0 -E < 1.patch && svn rm `svn st -q | grep ^! | cut -c 9-`
0
1

I think the OP's second issue is caused by an SVN bug that was fixed in SVN 1.7. You change a directory structure (move, rename, delete) and commit it, but when using svn diff, the patch seems to "do nothing".

I had this problem when deleting directories and the symptoms are the same so I'm assuming we are experiencing the same "root bug". For me, updating to svn 1.7 solved it, because svn 1.7 generates diffs (patches) differently.

Some versions of svn diff don't put the moved/renamed/deleted files in the diff at all!

See: http://svn.haxx.se/dev/archive-2004-03/0333.shtml. This archived email from the SVN DEV list shows the devs themselves identified this problem, sometime before 1.0.1 was released, over a decade ago. If you follow the thread, they seemed quite determined to fix it then, but even 1.6 was also leaving stuff out of the diff. I had to update to 1.7.

Basically, if svn < 1.7 detected that a directory was svn delete'd, it would not recurse and process the children, it would just stop there and not put anything under that tree in the diff. This is not what we want, we want explicit removes for ALL of the children, so that patch can, as mentioned in other answer, remove empty files and directories via -E. Patch can't do anything if the file isn't in the patch.

Using svn 1.7 I did an identical diff as I did before but every file under a deleted directory was explicitly in the patch as having all lines removed (emptying), and then patch/quilt successfully removed the files and folders. I'm assuming something similar needs to happen in your case with moving or renaming.

GOTCHAS: Upgrading to 1.7 will leave your working copies useless. Make sure you commit your changes before updating. Then you have to checkout everything again. Edit: The SVN 1.7 client might be able to repair your working directories but if it can't you might need to checkout again. Just be aware so you don't lose work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.