views:

636

answers:

3

I saw this posting which explained how to get BC3 working as the diff tool for Subversion... but what about using Beyond Compare 3 to do 3-way merge/compares?

+1  A: 

I only have experience with BC3 and TFS, so take this with a grain of salt. The 3-way merge was the only feature I had problems with. More than once I had to copy and paste the changes by hand in BC3 to finish the merge.

Larry Fix
I use BC3 through Tortoise on Windows. I can say that the decisions BC3 makes are consistently more accurate then Tortoise or the SVN cli itself. I also create custom profiles for certain file types/patterns that I want to override the defaults on.
Mike Miller
+2  A: 

To do this, create a batch file called (for example) diff3wrap.bat, and setup your diff3-cmd in your SVN config to point at it.

The following diff3wrap.bat file will do the job. It creates a temporary filename for the merge output and deletes it after returning the merged contents back to SVN.

@ECHO OFF

SET DIFF3="C:\Program Files\BeyondCompare3\BComp.exe"

REM Subversion provides the paths we need as the last three parameters
REM These are parameters 9, 10, and 11.  
REM Suitable titles for these three panes in the merge tool are in parameters 4, 6 and 8 respectively.


REM But we have access to only nine parameters at a time, so we shift our nine-parameter window
REM twice to let us get to what we need, thus changing the effective positions of the various parameters.
REM
SHIFT
SHIFT
SET MYTITLE=%2
SET OLDTITLE=%4
SET YOURTITLE=%6
SET MINE=%7
SET OLDER=%8
SET YOURS=%9
SET OUTPUTFILE=%OLDER%_%RANDOM%.merge

REM Call BeyondCompare to perform the actual merge
REM Note we give it a temporary output file and echo the output back out for SVN to use as the merged file
%DIFF3% /lefttitle=%MYTITLE% /centertitle=%OLDTITLE% /righttitle=%YOURTITLE% /outputtitle="Merge Output" %MINE% %YOURS% %OLDER% %OUTPUTFILE% 

if NOT %errorlevel% == 0 goto :mergenotcomplete

REM Merge complete. Echo the output to stdout for SVN to pick up as the result, then throw away the temporary file

TYPE %OUTPUTFILE%
del /f /q %OUTPUTFILE%
exit 0

:mergenotcomplete
exit 1
liamf
Based on what the SVN Redbook said about this, this looks right... I'll accept the answer as soon as I get to check it.
ceretullis
+1  A: 

I like liamf's batch file, but I think it could take a minor tweak:

I've added automerge and reviewconflicts to the command invocation, so that in case of a merge without conflicts it just closes without intervention - the UI will only pop-up to review conflicts.

Thus, the line in question becomes:

%DIFF3% /automerge /reviewconflicts /lefttitle=%MYTITLE% /centertitle=%OLDTITLE% /righttitle=%YOURTITLE% /outputtitle="Merge Output" %MINE% %YOURS% %OLDER% %OUTPUTFILE% 

cheers,
Claudio

Claudio A. Heckler