Thursday, November 25, 2010

Merging svn using Meld

Meld is a great tool, and it can ease the pain of svn greatly. Unfortunately, until recently (not yet in version 1.3), it did not support a merge result file argument.

But now it does! (still experimental and not officially released)

So how to use it (under linux, or unix compatible systems):
Check if your Meld is > 1.3, if not,
Check the meld website to see if Meld > 1.3 is released and install it.
If you got Meld > 1.3 go ahead with "SVN Meld glue".

Build Meld source


Fetch the Meld source and build it using:
cd ~/bin
git clone git://git.gnome.org/meld
cd meld
make
./bin/meld

If all went fine, you should be running Meld > 1.3 now. Close it off.

SVN Meld glue


Start a text editor.
Write the following to a file named ~/bin/svn-merge-meld
#!/usr/bin/env python
# svn merge-tool python wrapper for meld
import sys
import subprocess

# path to meld ($ which meld)
meld = "~/bin/meld/bin/meld"
log = False
f = open('/tmp/svn-merge-meld.log', 'a')

def main():
if log:
f.write("call: %r\n" % sys.argv)

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

# the call to meld
cmd = [meld, mine, base, theirs, merged]

# Call meld, making sure it exits correctly
subprocess.check_call(cmd)

try:
main()
except Exception as e:
print "Oh noes, an error: %r" % e
if log:
f.write("Error: %r\n" % e)
sys.exit(-1)
Change the file permissions to +x:
chmod +x ~/bin/svn-merge-meld

With the text editor, edit ~/.subversion/config
Locate this section:
### 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
Add this below it:
merge-tool-cmd = ~/bin/svn-merge-meld

Usage


svn merge -r 14829:HEAD http://path/to/trunk my/branch
Select: (p) postpone, (df) diff-full, (e) edit, (r) resolved,
(mc) mine-conflict, (tc) theirs-conflict,
(s) show all options:
Press l-Enter (the letter L) to fire up Meld.
In this case:
  • the left side is the change in my/branch
  • the middle part is the merge result which you can edit
  • the right side are the changes in the trunk
Merge, save and quit, then in the console press r-Enter, and your done. (Almost) painless merging in svn!

References


5 comments:

  1. it looks like the python indentation is wrong

    ReplyDelete
  2. @dani: I couldn't get it working either - merge-tool-cmd doesn't work with "~", and the indentation is missing. Working alternative.

    ReplyDelete
  3. try meld = "/usr/bin/meld"
    thats where it will be put by Linux installation packages (and the script has a Linux flavour too - I guess it wouldn't work on other platforms ;)
    don't forget to fix the python indentation..

    ReplyDelete
  4. Hi,
    Even after fixing the indentation and the meld path, it doesn't work. I get an error: The external merge tool exited with exit code 255

    Any idea what might be wrong??

    ReplyDelete
  5. For solve this problem "The external merge tool exited with exit code 255"

    You should specify full path to merge-tool-cmd in ~/.subversion/config
    for example:
    merge-tool-cmd = /home/_username_/bin/svn-merge-meld

    ReplyDelete