Sean Holmesby

.NET and Sitecore Developer

By

The MergeToolChooser Application: allowing alternative merge tools for different file types

The MergeToolChooser application was included with the installation of TDS Classic version 5.1 to assist in the setup of the Sitecore Item Merge Tool.
The application allows you to select alternative merge tools for different file types, meaning you can select one tool for .xml files, another tool for .cs files, and another for json files if you wanted to.

This is particularly useful when using a source control provider like Git which only allows for one merge tool by default. In this case, you would point Git’s Merge Tool to the MergeToolChooser application, then allow the MergeToolChooser to designate which merge tool should be used for the given file type.

The MergeToolChooser.exe can be found in
C:\Program Files (x86)\Hedgehog Development\Team Development for Sitecore (VS2017)
(or the folder of your latest Visual Studio version’s TDS Classic install)

Alongside it is a config file that configures the merge tool designation.
C:\Program Files (x86)\Hedgehog Development\Team Development for Sitecore (VS2017)\MergeToolChooserConfig.xml

By default, there are only two Merge Tools listed in there….the Sitecore Item Merge Tool, and KDiff3.

<?xml version="1.0" encoding="utf-8" ?>
<MergeToolChooserConfig>
  <!-- TDS Item Merge Tool -->
  <MergeTool Extension=".item" Cmd=".\SitecoreItemMerge.exe" Parameters="&quot;$1&quot; &quot;$2&quot; &quot;$3&quot; &quot;$4&quot;"/>
  <!-- Default entry -->
  <MergeTool Cmd="C:\Program Files\KDiff3\KDiff3.exe" Parameters="&quot;$1&quot; &quot;$2&quot; &quot;$3&quot; -o &quot;$4&quot;"/>
</MergeToolChooserConfig>

I’ve started putting together some examples of what other tools you might want to use in a copy of the MergeToolChooserConfig.xml file, here:-

https://gist.github.com/SaintSkeeta/051f119717b0f0f9bb1b770faf134879

(Feel free to let me know other tools and command parameters to throw in here.)
I’ve also posted how to this XML can be configured for any merge tool of your choosing.

You can see from this configuration that different Merge tools can be used for different file extensions.
Finally, the last entry has no extension attribute defined. This is the Default entry, which all other non-specified file types fall through to.

<MergeTool Cmd="C:\Program Files\KDiff3\KDiff3.exe" Parameters="&amp;quot;$1&amp;quot; &amp;quot;$2&amp;quot; &amp;quot;$3&amp;quot; -o &amp;quot;$4&amp;quot;</div>

To set this all up and follow the diagram above, you need to tell Git about the MergeToolChooser application.
Open your Global .gitconfig.
%USERPROFILE%\.gitconfig

Add the following

[mergetool "merge_chooser"]
    cmd = \"C:/Program Files (x86)/Hedgehog Development/Team Development for Sitecore (VS2017)/MergeToolChooser.exe\" \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\" \"Local\" \"Remote\" \"Original then Result (when field is selected)\"

(Note: Fix the path to your latest installed TDS Classic version)

Then set Git to use it use it as your chosen merge tool, in the .gitconfig add the setting (or change the existing setting) for ‘merge’ to be the new merge_chooser you just defined.

[merge]
    tool = merge_chooser

Now you can set different Git Merge tools for different file types in the MergeToolChooserConfig.xml.
If you find anything wrong with the parameters I’ve defined in the example Gist, or have any new ones to add, please let me know.

Leave a Reply

Your email address will not be published. Required fields are marked *