29

I've specified merge-tool-cmd = meld in my Subversion config. When I go to resolve a merge conflict using option l from the presented conflict resolution options, I receive the message:

meld: error: too many arguments (wanted 0-4, got 5)
The external merge tool exited with exit code 2

Can anyone diagnose the problem/provide a solution? Thanks.

4 Answers 4

45

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.

4
  • Remove os and shutil imports -- they are not used anymore.
    – bcelary
    Oct 18, 2013 at 12:22
  • 3
    Seems that the call cmd for meld has changed -- i use cmd = [meld, mine, base, theirs, '-o', merged] (meld 1.8.4). `
    – Ayrat
    Apr 20, 2015 at 10:08
  • Throwing away the error information with that catch isn't very useful. Feb 17, 2016 at 0:49
  • Great answer. I voted before, then now having been back 2nd time (the need to resolve svn conflict shows up again..) and wanted to vote again :)
    – artm
    Sep 19, 2017 at 11:38
11

The drevicko's answer is correct but requires Python. This answer is a 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 configuration:

vi ~/.subversion/config

and enable merge-tool-cmd:

[helpers]
merge-tool-cmd = /path/to/svn-merge-meld.sh
2
  • 1
    meld 3.18.0 only takes 3 arguments again. How to support that?
    – JohnyTex
    May 8, 2020 at 14:42
  • 2
    Thank you @JohnyTex for your bug report ;) Ten years ago, Meld accepted up to 4 input files for a four-way merge. But this is not possible any more (since v1.8.4 apparently). :'( I have fixed my answer. (I do not use SVN since many years)
    – oHo
    Apr 20, 2022 at 9:11
2

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

0

I updated @drevicko answer to work with subversion>=1.14, meld>=3.20 and Python 3:

#!/usr/local/bin/python3

# 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]
   merged1 = sys.argv[4]
   merged2 = sys.argv[5]

   print(14*"*" + " MELD was called with " + 14*"*")
   print(f"base    = {base}")
   print(f"theirs  = {theirs}")
   print(f"mine    = {mine}")
   print(f"merged1 = {merged1}")
   print(f"merged2 = {merged2}")

   # the call to meld
   cmd = [meld, mine, base, theirs, '-o', merged1, '--auto-merge', '-L', 'mine -> base(merged) <-theirs']

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

print(50*"*")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.