Refactoring and Branches in Subversion
December 6th, 2010To quote from the subversion documentation. “A common desire is to refactor source code, especially in Java-based software projects.” This might be one of your concerns too.
One problem I encountered using a branch from a refactored project was the following error when merging from the trunk:
$ pwd
myProjectBranch
$ svn merge http://myServer/svn/stijn/myProject/trunk
Cannot replace a directory from within.
To illustrate the problem we assume the following:
- myProject was created at revision 50
- myProject was refactored at revision 100
- myProjectBranch was copied from the trunk at revision 150
- myProjectBranch is now at revision 200 and we try to merge from the trunk
If you refactored enough the problem above will show up when doing:
$ pwd
myProjectBranch
$ svn merge http://myServer/svn/stijn/myProject/trunk
Cannot replace a directory from within.
The reason is that the merge operation tries to apply all diffs between revisions 0 and 200 to the branch. As there are files or directories that have disappeared or have been moved the problem arises when trying to apply these diffs to the branch.
The problem is to tell Subversion to ignore all diffs between 0 an the moment the copy was made (revision 150) as these were already applied when the branch was created. To do this one could manually edit all svn propedit svn:mergeinfo subversion properties. A better way to do this is using the following
$ svn merge http://myServer/svn/stijn/myProject/trunk -r1:150 --record-only
$ svn commit -m "Tricked subversion into ignoring all diffs between \\
1 and 150 (creation of branch) when merging"
An even better way is to directly do this after creation of the branch.