Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVN merge from trunk to branch results in tree conflicts

Assuming we have one trunk and one branch (COKE). (I run Git over SVN and merge from trunk to COKE with svn, not Git)

  1. There have been changes in FILE1 on trunk that we want in COKE branch.
  2. We merge from trunk and I commits the merge on COKE branch.
  3. Then FILE1 is deleted from trunk, I want that change in COKE.
  4. I merge and a tree conflict occurs on FILE1 on COKE branch.

Does this tree conflict occurs because of the commit with merge in (2)?

What could I do to fix this three conflicts?

svn resolve --accept theirs-full /path/FILE1 doesn't work, says only "working" is going to work.

like image 374
user1643192 Avatar asked Oct 06 '22 18:10

user1643192


2 Answers

There should be no tree conflict in this scenario unless certain merge-tracking information is missing.

In order to check this, run the following command:

$ svn switch ^/branches/COKE
$ svn mergeinfo --show-revs=merged ^/trunk

This prints a list of revisions merged from trunk into the COKE branch. Can you find there a revision when you've modified FILE1 at trunk? Most probably there's no that revision.

It's a common case when SVN user merges modification from one branch into another, but then commits not the whole working copy (i.e. including the root directory) rather just those files modified by merge.

Wrong:

$ svn merge ^/trunk
--- Merging r5 through r6 into '.':
M    file.txt
--- Recording mergeinfo for merge of r5 through r6 into '.':
 U   .
$ svn commit FILE1

The problem is that the root directory stores svn:mergeinfo property. Subversion uses this property to track merges, so you have to commit the whole working copy.

Right:

$ svn merge ^/trunk
--- Merging r5 through r6 into '.':
M    file.txt
--- Recording mergeinfo for merge of r5 through r6 into '.':
 U   .
$ svn commit .

When you tried to merge trunk into the COKE branch the second time, Subversion detected that FILE1 was deleted at trunk and at the same time it was modified at COKE branch (by step 2). As result it marked the file with a tree conflict (local edit, incoming delete upon merge).

How to fix that?

Now you have to fix the merge-tracking information for the branch COKE. In order to do that repeat the step 2 with --record-only option and a proper revision specified:

$ svn merge --record-only -cN ^/trunk
--- Recording mergeinfo for merge of r5 through r6 into '.':
 U   .
$ svn commit .

Where N is the modification of FILE1 in trunk you were trying to merge.

like image 186
vadishev Avatar answered Oct 10 '22 02:10

vadishev


vadishev's answer gave me the knowledge to create this script, which should automatically add the missing mergeinfo for you.

Make sure pwd is the branch root, then run this:

trun="path/to/trunk/root"
for i in `svn mergeinfo --show-revs=merged $trun | sed 's/^r//g'`
do 
  echo "working on $i"
  svn merge --record-only -c$i $trun
done

Or, as a oneliner:

trun="../../trunk/tetracosm"; for i in `svn mergeinfo --show-revs=merged $trun | sed 's/^r//g'`; do echo "working on $i"; svn merge --record-only -c$i $trun; done
like image 36
ACK_stoverflow Avatar answered Oct 10 '22 04:10

ACK_stoverflow