Search code examples
mergemercurialdiffbranching-and-mergingmerge-conflict-resolution

How to set up Diffuse as Mercurial's 3-way merge tool and save from the middle pane into target


I am using Mercurial (on a Debian system) with Diffuse as the merge tool of choice for handling 3-way merges. However, with the default setup from thg's mergetools.rc (at https://bitbucket.org/tortoisehg/thg/src/8d587fe951d9dd9ad41f532151a0d17372535d01/contrib/mergetools.rc#lines-243 ), Mercurial passes $local in the first pane, $base in the second pane, and $other in the third pane. $local is the actual file in the repository, both of the others are files in /tmp with names like "FILENAME~base.XXXXXX.EXT" respectively "FILENAME~other.XXXXXX.EXT".

Now from how I understand 3-way merges generally and Diffuse specifically, including the fact that Diffuse defaults to focus the middle pane on startup, it seems to me I'm supposed to pull changes from the (left←) first pane (local) and (right→) last pane (other) into the middle pane (base), then save that as the target file in the actual repo.

This target file, as mentioned, is actually passed by hg into the first pane. Therefore, to do that with the default setup, I need to "Save File As..." the middle pane and then manually enter the pathname of the target file. At least, that's what I have done until today. This is obviously uncomfortable.

Some other merge tools seem to allow specifying an output (target) filename with an "-o" switch, but Diffuse doesn't have such a switch. So, my question is, how am I supposed to set up and use Diffuse with Mercurial to avoid this uncomfortable Save File As dance?


Solution

  • I created a script that swaps the files and then calls Diffuse with the names that (to hg) are $base $local $other, in that order. This means the middle pane receives the "$local" filename (really BASE then), which is the target that I want to save the middle pane into. It's at https://bitbucket.org/ecm/diffuse-swap/commits/fdd8357ab5a1fb7e1743e169fa11c3ec7f635e97

    (I'd pondered asking the question here before settling on this solution. I didn't find anyone else having this problem on the web, so I want to provide my question and answer for anyone else with the same problem. That's why I am answering my own question.)