How to set up svn conflict resolution with meld?

The drevicko's answer is correct but requires Python. This answer is a bash script alternative:

#!/bin/bash

base=${1?1st arg is the 'base' file}
theirs=${2?2nd arg is 'theirs' file}
mine=${3?3rd arg is 'mine' file}
merged=${4?4th arg is the 'merged' file}

cat "$mine" > "$merged"

meld -L "Base=${base##*/}"           "$base"   \
     -L "Mine->Merged=${merged##*/}" "$merged" \
     -L "Theirs=${theirs##*/}"       "$theirs" \
     -o "$merged"

Copy the above script in file svn-merge-meld.sh and provide execution permission with:

chmod +x svn-merge-meld.sh

Finally edit your svn configuration:

vi ~/.subversion/config

and enable merge-tool-cmd:

[helpers]
merge-tool-cmd = /path/to/svn-merge-meld.sh

First a warning! It is very easy to end up losing your local edits if you get this wrong! Test test test!

I'm afraid the script from pmod's link does not work with svn 1.6 (current in Ubuntu 11.04). Putting together code from pmod's link and here and advice here, I made this script that seems to work ok:

#!/usr/bin/env python
# svn merge-tool python wrapper for meld
import sys
import subprocess

try:
   # path to meld
   meld = "/usr/bin/meld"

   # file paths
   base   = sys.argv[1]
   theirs = sys.argv[2]
   mine   = sys.argv[3]
   merged = sys.argv[4]

   # the call to meld
   # For older meld versions:
   # cmd = [meld, mine, base, theirs, merged]
   # New meld versions: >= 1.8.4
   cmd = [meld, mine, base, theirs, '-o', merged]

   # Call meld, making sure it exits correctly
   subprocess.check_call(cmd)
except:
   print "Oh noes, an error!"
   sys.exit(-1)

Save this somewhere sensible (eg /usr/local/bin/svn-merge-meld.py) and make it executable:

sudo chmod +x /usr/local/bin/svn-merge-meld.py

Then edit ~/.subversion/config and uncomment the line merge-tool-cmd =, and set the path to your command.

Note that when a conflict occurs, you will be prompted what to do with it. You need to type a single l and for svn to run this script. When you've finished your merge, you need to type an r to resolve the conflict and copy the merged version to the working copy.


You need to use wrapper script to grab and put things subversion is out to the order needed for your diff tool (check this):

The key to using external two- and three-way differencing tools (other than GNU diff and diff3, of course) with Subversion is to use wrapper scripts, which convert the input from Subversion into something that your differencing tool can understand, and then to convert the output of your tool back into a format that Subversion expects—the format that the GNU tools would have used. ...

Subversion calls external diff programs with parameters suitable for the GNU diff utility, and expects only that the external program will return with a successful error code. For most alternative diff programs, only the sixth and seventh arguments—the paths of the files that represent the left and right sides of the diff, respectively—are of interest.

This is very well described here

Tags:

Svn

Meld