Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set kdiff3 as merge tool for SVN

I would like to be able to resolve conflicts using kdiff3, when SVN notifies me about the conflict. How can I set it as a default tool for this?

like image 929
gruszczy Avatar asked Jan 26 '11 11:01

gruszczy


People also ask

How do I merge KDiff3?

KDiff3 offers automatic merge for these items at Merge item in the settings dialog. For simple lines that match the Auto merge regular expression option in all input-files KDiff3 will choose the line from B or - if available - from C.

What is ABC in KDiff3?

A refers to the version your merge target is based on. If you Merge from branch to trunk, 'A' will be the previous trunk version. B is what you currently have in your local trunk folder, including local changes. C is the Version you wanna merge on top of B.


2 Answers

Go to the Subversion configuration file (/etc/subversion/config or ~/.subversion/config), and set merge-tool-cmd variable with your favourite tool:

### Set merge-tool-cmd to the command used to invoke your external ### merging tool of choice. Subversion will pass 4 arguments to ### the specified command: base theirs mine merged # merge-tool-cmd = merge_command 

Although there is a problem with kdiff3 which does not support four plain arguments (SVN passes four plain arguments to kdiff3, and it does not work), so it is usually called with a simple script to translate the arguments, e.g., "kdiff3caller":

#!/bin/sh kdiff3 "$1" "$2" "$3" -o "$4" 

This kdiff3 problem and solution is explained here.

like image 129
Jon Ander Ortiz Durántez Avatar answered Sep 22 '22 13:09

Jon Ander Ortiz Durántez


A solution that is shorter and works with later versions of SVN (tested on SVN 1.7.7):

Create a script ~/svn-merge-kdiff

#!/bin/bash  # Useful when something fails LOG=~/svn-merge-kdiff-last-run.log echo "arguments passed to $0: $@" > $LOG  # Now, don't think you will get the $1, $2, etc... by referencing. # At first, you have to copy it to an array for i in $@; do     args=( ${args[@]} $i ) done  echo "parsed args" >> $LOG for i in ${args[@]}; do     echo $i >> $LOG done  # I keep it in case something changes if [ "${args[1]}" == "-m" ] && [ "${args[2]}" == "-L" ] && [ "${args[3]}" == ".mine" ];then     command="kdiff3 --L1 ${args[5]} --base ${args[9]} --L2 ${args[7]} ${args[10]} --L3 ${args[3]} ${args[8]} -o merged"     $command     if [[ $? -ne 0 ]]; then         echo "$command failed" >> $LOG         exit 1     fi      # You have to do this, otherwise after the merge you will see... empty file(?)     cat merged      rm merged     exit 0 fi  exit -1 

Bind it to svn in ~/.subversion/config

diff3-cmd = ~/svn-merge-kdiff 
like image 29
Adam Avatar answered Sep 22 '22 13:09

Adam