23

How do I configure Apple's FileMerge program to function as Mercurial's merge tool? I have my .hgrc file setup in my home directory and I simply want to configure FileMerge as the merge program.

5 Answers 5

28

As described in the hg wiki, this has worked for me with various versions of hg:

  • Create a script somewhere in your $PATH, say in /usr/local/bin:
$ vim /usr/local/bin/opendiff-w

#!/bin/sh
# opendiff returns immediately, without waiting for FileMerge to exit.
# Piping the output makes opendiff wait for FileMerge.
opendiff "$@" | cat
  • Add the following sections to your ~/.hgrc:
[extdiff]
cmd.interdiff = hg-interdiff
cmd.opendiff = opendiff-w

[merge-tools]
filemerge.executable = opendiff-w
filemerge.args = $local $other -ancestor $base -merge $output

[extensions]
extdiff = 

Now you can use it as $hg opendiff.

7
  • 10
    For others: opendiff-w is the script file which end up being referenced in the .hgrc file (this wasn't too obvious to me). The first code block is the contents. Also, changed the permissions to add execute chmod +x opendiff-w
    – Frank V
    Aug 27, 2009 at 1:11
  • 5
    For others: Something that was not obvious to me: You now need to run $hg opendiff (to see the output in FileMerge); $hg diff will still show you the output on the command line Jun 24, 2011 at 12:19
  • 5
    For others: ... and you need to enable extdiff extension in ~/.hgrc Jun 24, 2011 at 12:34
  • For others. Make the opendiff-w executable with chmod a+x opendiff-w
    – elliotrock
    Jul 4, 2016 at 4:36
  • 1
    [extensions] extdiff = is to load the extension, as far as I understand.
    – Roberto
    Mar 14, 2018 at 23:12
2

Update: The Mercurial wiki has a page about FileMerge. Read that first.

I haven't tried to use FileMerge but a general overview might help. Most of what you want to know is described at the Mercurial wiki's MergeProgram page. The short version is your typical choices are:

Set the HGMERGE environment variable to point at the merge tool you want.

or, add the following to your .hgrc:

 [ui]
 merge = /path/to/toolname

 [merge-tools]
 toolname.args = $base $local $other

The key is that a merge tool needs to take three arguments: the base revision, your local changes, and the changes from the other branch. You use the first configuration to specify the tool, and the second to specify how it takes arguments.

1

None of the documentation linked worked for me without modifications; eventually what I ended up doing was a combination of the official instructions and "Using Vim as the filemerge program" from https://www.mercurial-scm.org/wiki/TipsAndTricks. I created the opendiff-w script described in this answer (though I named it hgvdiff), and put the following into my .hgrc:

[extdiff]
cmd.interdiff = hg-interdiff
cmd.opendiff = /usr/local/bin/hgvdiff

[merge-patterns]
** = filemerge

[merge-tools]
filemerge.executable = /usr/local/bin/hgvdiff
filemerge.args = $local $other -ancestor $base -merge $output
filemerge.checkchanged = true
filemerge.gui = true

[extensions]
extdiff =

This is moderately functional, though it sometimes performs the check for whether a file was changed prematurely, leading to a bunch of:

 output file wwwroot/zoomingo/website/protected/messages/en/z.php appears unchanged
was merge successful (yn)? n

when you close FileMerge.

0

Here is how I fixed it:

Created /usr/local/bin/opendiff-w filled with:

#!/bin/sh
# opendiff returns immediately, without waiting for FileMerge to exit.
# Piping the output makes opendiff wait for FileMerge.
opendiff "$@" | cat

Then ran the command: sudo chmod +x /usr/local/bin/opendiff-w

Then edited ~/.hgrc with the following addition:

[extdiff]
cmd.interdiff = hg-interdiff
cmd.opendiff = opendiff-w

[merge-tools]
filemerge.executable = /usr/local/bin/opendiff-w
filemerge.args = $local $other -ancestor $base -merge $output

[extensions]
extdiff = 

Then I ran the following command to check wether it worked: hg opendiff

However, I got the following error:

exception raised trying to run FileMerge: launch path not accessible

In order to fix it I ran the following command:

sudo /usr/bin/xcode-select -switch /Applications/Xcode.app/Contents/Developer/

This should now work and open up FileMerge.

====================================================================

If you're using TorsoiseHg for Mac, the only thing you need to do now in order to work with FileMerge is to choose filemerge from the Detected merge/diff tools when the Resolve Conflict window appears and choose Tool Resolve.

enter image description here

Hope this helps.

-1

I haven't tried it, but I'm betting you need to point all the way to the FileMerge executable, not just the app bundle.

So:

[ui]  
merge = /Developer/Applications/Utilities/FileMerge.app/Contents/MacOS/FileMerge
1
  • I tried it as well, I got: FileMerge[51550:30f] Couldn't create connection for root
    – jammon
    Sep 12, 2011 at 5:43

Your Answer

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

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