Sourcetree fails to open Diffmerge for merge conflicts
Asked Answered
C

3

7

Recently I had a fresh install of macOS. I've installed Sourctree and diffmerge and set diffmerge as the default merge tool. For some reason everytime when I select 'Resolve Conflicts -> Open External Merge Tool' sourcetree opens its waiting view and directly closes it.

My settings page in sourcetree:

enter image description here

This is how my root .gitconfig looks like when sourcetree configures diff merge for me:

[core]
    excludesfile = /Users/[username]/.gitignore_global
[user] 
    name = ---- -----
    email = [email protected]
[commit]
    template = /Users/[username]/.stCommitMsg
[credential]
    helper =  !/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/java -Ddebug=false -Djava.net.useSystemProxies=true -jar /usr/local/Cellar/git-credential-manager/2.0.4/libexec/git-credential-manager-2.0.4.jar

[difftool "DiffMerge"]
[mergetool "DiffMerge"]
[diff]
    tool = diffmerge
[difftool "diffmerge"]
    cmd = /usr/local/bin/diffmerge \"$LOCAL\" \"$REMOTE\"
[merge]
    tool = diffmerge
[mergetool "diffmerge"]
    trustExitCode = true
    cmd = /usr/local/bin/diffmerge --merge --result=\"$MERGED\" \"$LOCAL\" \"$BASE\" \"$REMOTE\"
[difftool "sourcetree"]
    cmd = /Applications/DiffMerge.app/Contents/MacOS/DiffMerge/Contents/MacOS/DiffMerge --nosplash \"$LOCAL\" \"$REMOTE\"
path = 
[mergetool "sourcetree"]
    cmd = /Applications/DiffMerge.app/Contents/MacOS/DiffMerge/Contents/MacOS/DiffMerge --merge --result=\"$MERGED\" \"$LOCAL\" \"$BASE\" \"$REMOTE\"
    trustExitCode = true
Coralloid answered 11/11, 2018 at 14:50 Comment(0)
C
22

This happend to me when diffmerge was installed via the pkg install instead of the installer. This appearantly does not configure your bash to know the command diffmerge so than you have to set the path to the diffmerge (or update your bin config).

To solve this I manually configured Visual Diff Tool and Merge Tool (with as benefit that you can disable that annoying splash screen on launch everytime).

Settings page in sourcetree

enter image description here

Diff

Command: /usr/local/bin/diffmerge Arguments --nosplash "$LOCAL" "$REMOTE"

Merge

Command: /usr/local/bin/diffmerge Arguments --nosplash --merge --result="$MERGED" "$LOCAL" "$BASE" "$REMOTE"

The --nosplash argument is optional but prevents the (in my opinion useless) pop up that you always have to close before you can start your work.

Git config file:

[core]
    excludesfile = /Users/[username]/.gitignore_global
[user]
    name = ---------
    email = [email protected]
[commit]
    template = /Users/[username]/.stCommitMsg
[credential]
    helper = !/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/java -Ddebug=false -Djava.net.useSystemProxies=true -jar /usr/local/Cellar/git-credential-manager/2.0.4/libexec/git-credential-manager-2.0.4.jar

[difftool "DiffMerge"]
[mergetool "DiffMerge"]
[diff]
    tool = diffmerge
[difftool "diffmerge"]
    cmd = /usr/local/bin/diffmerge \"$LOCAL\" \"$REMOTE\"
[merge]
    tool = diffmerge
[mergetool "diffmerge"]
    trustExitCode = true
    cmd = /usr/local/bin/diffmerge --merge --result=\"$MERGED\" \"$LOCAL\" \"$BASE\" \"$REMOTE\"
[difftool "sourcetree"]
    cmd = /usr/local/bin/diffmerge --nosplash \"$LOCAL\" \"$REMOTE\"
    path = 
[mergetool "sourcetree"]
    cmd = /usr/local/bin/diffmerge --nosplash --merge --result=\"$MERGED\" \"$LOCAL\" \"$BASE\" \"$REMOTE\"
    trustExitCode = true

More info about diffmerge command line arguments:

Diff: https://sourcegear.com/diffmerge/webhelp/sec__clargs__diff.html

Merge: https://sourcegear.com/diffmerge/webhelp/sec__clargs__merge.html

Coralloid answered 11/11, 2018 at 14:50 Comment(3)
Note that "Diff Command" may vary depending on where your diffmerge binary is located, in my case, it was: /Applications/DiffMerge.app/Contents/MacOS/DiffMergeScup
For me I could not use the --nosplash option. It would popup with a "not found" error in "/var/folders". But once I took out --nosplash for the custom diffmerge option, it then worked. Also, I did not quote the variables.Gusti
The issue I had was brought up here: https://mcmap.net/q/1475272/-diffmerge-is-unable-to-find-sourcetree-files-trying-to-resolve-conflicts Removing --nosplash solved it.Gusti
V
3

I resolved this problem by following the instructions on the DiffMerge Settings for OS X documentation page, which was:

First confirm that /usr/local/bin/diffmerge is present. If you used the PKG Installer, this was installed when /Applications/DiffMerge.app was installed. If you used the DMG file, refer to the instructions for installing the Extras.

The following commands will update your .gitconfig to let GIT use DiffMerge:

$ git config --global diff.tool diffmerge
$ git config --global difftool.diffmerge.cmd
    "/usr/local/bin/diffmerge \"\$LOCAL\" \"\$REMOTE\""

$ git config --global merge.tool diffmerge
$ git config --global mergetool.diffmerge.trustExitCode true
$ git config --global mergetool.diffmerge.cmd 
    "/usr/local/bin/diffmerge --merge --result=\"\$MERGED\"
        \"\$LOCAL\" \"\$BASE\" \"\$REMOTE\""

I was then able to use DiffMerge by choosing the menu option in Sourcetree

Sourcetree preference pane, showing the Diff tab, with DiffMerge selected for the Visual Diff Tool and Merge Tool options

(Optional) You may want to add --nosplash to both commands, before other parameters, to avoid the splash screen (as also recommended by @saren-inden). i.e.;

$ git config --global diff.tool diffmerge
$ git config --global difftool.diffmerge.cmd
    "/usr/local/bin/diffmerge --nosplash \"\$LOCAL\" \"\$REMOTE\""

$ git config --global merge.tool diffmerge
$ git config --global mergetool.diffmerge.trustExitCode true
$ git config --global mergetool.diffmerge.cmd 
    "/usr/local/bin/diffmerge --nosplash --merge --result=\"\$MERGED\"
        \"\$LOCAL\" \"\$BASE\" \"\$REMOTE\""
Villarreal answered 13/8, 2019 at 10:48 Comment(0)
A
0

I got the same issue. DiffMerge is not launched either when I click External Diff.

The problem seems to be the path of DiffMerge in .gitconfig file: cmd = /Applications/DiffMerge.app/Contents/MacOS/DiffMerge/Contents/MacOS/DiffMerge ....

If you check the path /Applications/DiffMerge.app/Contents/MacOS/DiffMerge, it's actually not a directory but a file. It seems SourceTree adds /Contents/MacOS/DiffMerge twice on the path. I removed the duplicate part and the External Diff starts working.

Haven't tried merge.

Affix answered 2/11, 2020 at 16:28 Comment(2)
If I do this and restart SourceTree, it re/instates the duplicate part. How to remove it for good_Audette
@Audette define custom diff tool as mentioned in Saren Inden's solution. Just copy correct cmd and arguments for diffMerge to sourcetree settings.Affix

© 2022 - 2024 — McMap. All rights reserved.