It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Configuring multiple external diff tools based on extension? Edited

I have multiple different binary filetypes that require different programs to diff and merge. I would like to be able to launch the proper diff program when right-clicking a file and selecting `External Diff`.

I already have all the different difftools and mergetools setup in my global config like so:


# Differencing Configuration
tool = WinMerge
[difftool "WinMerge"]
cmd = \"C:\\Program Files\\WinMerge\\WinMergeU.exe\" -e -u -dl \"Old $BASE\" -dr \"New $BASE\" \"$LOCAL\" \"$REMOTE\"
trustExitCode = true
[difftool "sourcetree"]
cmd = '' \"$LOCAL\" \"$REMOTE\"
[difftool "LogixCompare"]
cmd = \"C:\\Program Files (x86)\\Rockwell Software\\Logix Designer Tools\\Logix Designer Compare Tool\\RSLCompare.exe\" \"$LOCAL\" \"$REMOTE\" -PM FastestCompare


I also setup the extensions in gitattributes like `*.acd binary diff=LogixCompare`, but doing an external diff on such a file still just opens WinMerge (my default difftool as shown above).

EDIT: I now know that gitattributes only launches a diff driver which is different from a difftool. I guess the best I can hope for is a new feature in SourceTree that would allow us to select one of the configured difftools as an "advanced" External Diff. `git difftool --tool-help` will list the available built-in and user configured tools, so maybe SourceTree can use that to populate the list or directly read them from the global config file?


2 answers

1 accepted

0 votes
Answer accepted
Mike Corsaro Atlassian Team Jun 04, 2019

Hello! Sourcetree doesn't currently support this feature, but we appreciate the suggestion!


However, that doesn't mean it's impossible to accomplish this. You can use the "Custom Difftool" setting to point to a script you've created to allow custom diff tools to launch depending on the file type. You can find the logic for this idea here. Just be sure to configure ST to point to that script.

I had to do some playing around to actually get the path formatting and everything to work on Windows. This is my difftool entry:

[difftool "ExtSelector"]
cmd = \"C:\\Program Files\\Git\\\" \"$MERGED\" \"$BASE\" \"$LOCAL\" \"$REMOTE\"

And this is the contents of that script that finally didn't complain about paths and succeeded every time:




shopt -s nocasematch
case "${EXTENSION,,}" in
C:/Program\ Files\ \(x86\)/Rockwell\ Software/Logix\ Designer\ Tools/Logix\ Designer\ Compare\ Tool/RSLCompare.exe $LOCAL $REMOTE -PM FastestCompare
C:/Program\ Files/WinMerge/WinMergeU.exe -e -u -dl Local -dm Base -dr Remote $LOCAL $BASE $REMOTE -o $MERGED

exit $?

 Note that I pass the file path variables already quoted, so they are unquoted when used in the script. I went ahead and passed all three file versions to Winmerge, so most would probably pair that down to just Local and Remote.

Mike Corsaro Atlassian Team Jun 21, 2019

Nice work! Thanks for sharing your solution!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Sourcetree

Sourcetree for Windows - CVE-2019-11582 - Remote Code Execution vulnerability

A vulnerability has been published today in regards to Sourcetree for Windows.  The goal of this article is to give you a summary of information we have gathered from Atlassian Community as a st...

4,910 views 0 12
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you