Monday, December 10, 2012

Fixing a tree conflict in svn

This comes up often enough to be a problem, but not so often that I remember the fix.

The situation: The team is working on a development branch, is doing daily merges from trunk to the branch, and is making bug fixes on trunk. New files are added to trunk, and also added to the branch. This add on the branch was done manually, rather than adding just to trunk and then merging.

The problem: To do the daily merge from trunk, I change into a local directory that has the branch code then run

svn merge --dry-run http://server/path/trunk

The usual svn output shows a few conflicts:

danson$ svn merge --dry-run http://server.path/trunk
--- Merging r2733 through r2767 into '.':
C    path/file1.xml
C    path/file2.xml
C    path/file3.xml
C    path/file4.xml
   C path/dir1
C    path/file5.xml
U    path/file6.jsp
U    path/file7.jsp
A    path/file8.jsp

... snip ...
Summary of conflicts:
  Text conflicts: 5
  Tree conflicts: 1


It's that 5th line that is the tree conflict. Cleaning up the other conflicts, then running svn status still shows this:

A  +    path/dir1
A  +    path/dir1/file1.jsp
A  +    path/dir1/file2.xml
A  +    path/dir1/file3.xml
A  +    path/dir1/file4.xml
      C path/dir1
      >   local add, incoming add upon merge


It's possible to get other messages here, depending on what has happened. For example, if a file or directory has been deleted in the branch, but still exists in trunk, you would see:

local delete, incoming edit upon merge

The solution: Since these are new files and the files are identical in both the branch and in trunk, all that needs to happen is to tell svn that one or the other are acceptable. I'll use the branch version since I'm already in that directory:

danson$ svn resolve --accept working path/dir1
Resolved conflicted state of 'path/dir1'

That's it. Build, test, and commit as usual. In the case where the files are actually different, you might want to use something other than 'working' as the argument to --accept. The full list of arguments is here.

No comments: