Using TortoiseMerge in Linux and Mac OS

When I was using Tortoise SVN many years ago, I got used to its integrated merge conflict resolution tool TortoiseMerge. Since then I have tried many other merge tools, but I still consider it to be the best. I find that it can handle even complex merges and its merge results are very trustworthy (which I cannot say about most other merge tools).

That's why I continue using it, even though it was originally only available for Windows. With the help of Wine, it works well on Linux and Mac OS. In this post I would like to describe how to install and integrate it with Git.

Wine

TortoiseMerge can be run on Linux or MacOS using Wine (which is an API compatibility layer for running Windows applications on Unix-like operating systems).

Wine should be installed together with winetricks (which is a set of scripts to help install Windows apps on Wine). On Arch Linux, this can be done with:

sudo pacman -S wine winetricks

On MacOS it can be done with Homebrew:

brew install wine
brew install winetricks

Wine prefix

Wine has a concept of “prefixes” which are isolated environments for Windows apps. Using a separate prefix for each app ensures that applications don't affect each other, and it makes it much easier to remove apps.

There is a default prefix (~/.wine), but I like to make separate prefixes for every application that I run via Wine. I usually create Wine prefixes in a per-application directory under ~/opt.

mkdir -p ~/opt/tortoisemerge/wineprefix

To use the prefix, the WINEPREFIX environment variable should be set when running wine-related commands. This variable contains the path where the prefix should be stored. Wine will automatically create and populate if necessary.

Configuring Wine

I usually change some Wine's defaults right after initializing it. I especially don't like that it defaults to 96 DPI which makes fonts too small for modern monitors.

To fix it:

  1. Run winecfg

    WINEPREFIX=~/opt/tortoisemerge/wineprefix winecfg
    
  2. In the Graphics tab of the Wine configuration window change the DPI to a more appropriate values. E.g., 2x scale equals 192 DPI.

    Winecfg, graphics tab

Installing TortoiseMerge on Linux and Mac OS

The latest version of TortoiseMerge is distributed as a part of TortoiseSVN.

  1. Install some required Windows libraries that are missing from Wine:

    WINEPREFIX=~/opt/tortoisemerge/wineprefix winetricks uiribbon
    
  2. Download the installer from https://tortoisesvn.net/downloads.html. I'm using the x86-64 version.

  3. Install it in Wine (set the filename to the actual installer filename):

    WINEPREFIX=~/opt/tortoisemerge/wineprefix wine ~/Downloads/TortoiseSVN-1.14.7.29687-x64-svn-1.14.3.msi
    

    This will pop up the typical Windows installer, just press “Next” a couple of times.

  4. Check that everything works after installation:

    WINEPREFIX=~/opt/tortoisemerge/wineprefix wine ~/opt/tortoisemerge/wineprefix/drive_c/"Program Files"/TortoiseSVN/bin/TortoiseMerge.exe
    

    The TortoiseMerge window should appear:

    TortoiseMerge initial window

Integration with Git

TortoiseMerge works, now we need to tell Git to use it as a diff and merge tool.

git config --global mergetool.tortoisemerge.cmd 'WINEPREFIX=~/opt/tortoisemerge/wineprefix wine ~/opt/tortoisemerge/wineprefix/drive_c/"Program Files"/TortoiseSVN/bin/TortoiseMerge.exe -base "$BASE" -mine "$LOCAL" -theirs "$REMOTE" -merged "$MERGED"'
git config --global difftool.tortoisemerge.cmd 'WINEPREFIX=~/opt/tortoisemerge/wineprefix wine ~/opt/tortoisemerge/wineprefix/drive_c/"Program Files"/TortoiseSVN/bin/TortoiseMerge.exe -mine "$LOCAL" -theirs "$REMOTE"'

git config --global merge.tool tortoisemerge
git config --global diff.tool tortoisemerge

After that Git will use TortoiseMerge as a default merge and diff tool.