external diff stopped working
Asked by scottbrogden:

External diff stopped working recently for me. I have beyond compare selected in source tree options, I've tried multiple, win merge, ... no difference. I have "allow source tree to modify global git config" checked.

But I never see the .gitconfig file updated. I've manually added diff tools to it and it works from command line.

\[difftool "sourcetree"\]  
cmd = 'C:\\\\Program Files\\\\Beyond Compare 4\\\\BCompare.exe' \\"$LOCAL\\" \\"$REMOTE\\"

I can see beyond compare making the call

|---------------------------------------------------------------------------------------------------------------------------------------|
| ``` git -c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks difftool -y --tool=sourcetree raptor_kubedbg.xml ``` |

I can manually run this and it works. But when running from within sourcetree the process log shows

Unknown merge tool sourcetree  
fatal: external diff died, stopping at rcs.raptor.player/Properties/launchSettings.json

I feel like the root of the issue is sourcetree is not writing to the global git config correctly, is it supposed to?

Any suggestions? Running sourcetree version 3.0.17 beta 2660, was running 3.0.12 I think before this.


Answers:
author: scottbrogden
body: I've tracked this down to the environment variables HOMEPATH and HOMEDRIVE being incorrect. I can temporarily fix these and saving the diff app and doing the external diff work as expected.

Now to figure out why those values are incorrect.

One thing is running the same commands outside of sourcetree and they work. But when running from within sourcetree they don't work, so sourcetree is passing those environment variables into git.

comments: author: David French
body: I had the same issue. I think that Sourcetree assumes that %HOMEDRIVE%%HOMEPATH% points to your Windows user folder, where your .gitconfig file typically resides. But I think maybe they should have used %USERPROFILE% instead. My organization had set %HOMEDRIVE%%HOMEPATH% to a network drive location ([probably via Active Directory](https://social.technet.microsoft.com/Forums/windows/en-US/e9d9cd4d-6882-459e-b7a8-7091cfa031d2/where-are-user-environment-variables-homedrive-homepath-set?forum=winserverTS)), which caused this problem for me. My workaround was to remap my network drive to my home/user directory (since my organization has since quit using that mapped network drive anyways, but I didn't want to redefine those variables to be safe, since they were probably set by Active Directory). I remapped it in cmd with the command "subst \[drive to map\] %USERPROFILE%", then closed and re-opened Sourcetree, changed my diff/merge tool at that point, which successfully updated my .gitconfig (finally!). And then I also noticed that even after Sourcetree updated my .gitconfig, I still needed to keep that drive mapped (i.e. have homedrive/homepath point to my user folder) for the external diff/merge to continue to work.


author: Jeffrey Reaume
body: Had this happen due to to the Active Directory being disconnected when VPN was down/rebooted machine. Clicked on drive in Windows Explorer, drive reconnected, diff tool now works again in Sourcetree and git-gui.


author: bgannin
body: Hi Scott,

Beta discussions should be on the [mailing list](https://groups.google.com/forum/#!forum/atlassian-sourcetree-beta) and bug reports can go in the [bug tracker](http://jira.atlassian.com/browse/SRCTREEWIN/) per the list intro.

Thanks,

Brian Ganninger  
Senior Mac Developer, Sourcetree

comments: author: scottbrogden
body: I updated to the beta to see if it made any difference, it didn't. Using version 3.0.12 now and i'm seeing the issue.


author: S?ndor K?tai
body: I had the same issue. I use Source Tree 3.1.2 on Windows 10 and want to use CompareIt as external diff tool.

When I set the path in Source Tree, I get the same "*Unknown merge tool sourcetree*" message in the process output window.

I have two gitconfig files on my PC:

* c:\\Users\\\<username\>\\.gitconfig
* c:\\Program Files\\Git\\mingw64\\etc\\gitconfig

I don't know where Source Tree keeps the 'Diff Command' settings, but it is not in these files above. When I manually add:

```
[difftool "sourcetree"]
    cmd = 'c:/CompareIt/wincmp3.exe' $LOCAL $REMOTE 
```

to the 2nd gitconfig file (program files/git..) external diff started to work as expected.

Ps: When I go back to Source Tree external diff settings and change the path to something else:

* the new value is saved in Source Tree
* gitconfig files are not updated
* external diff still works with the path defined in 2nd gitconfig file (program files\\git..)

comments: author: Jonathan Demeyer
body: I also had issues with SourceTree 3.1.2 on Windows 10. I had several lines like this :

```
    cmd = 'C:/Program
```

In section \[difftool "sourcetree"\] and \[mergetool "sourcetree"\] in the file C:\\Users\\\<username\>\\.gitconfig

After cleaning those lines, I was back to an expected behaviour.


author: Terris Linenbach
body: Although I got it working for a 2019 release, external diffmerge has been broken for over a year now on macOS in subsequent releases. Some people use this tool contrary to what Atlassian thinks. It's a nice product that generates no revenue. Please open source it and let someone else take it on. Most of us here pay quite a lot for JIRA every month. Give back to OSS.


author: noamgr
body: I'm using Beyond Compare 4 and SourceTree 3.3.9 on Windows 10.

I had the same problem - no response after selecting External Diff from SourceTree.

By combining all the answers here, I found that the following lines in the file gitconfig make it work:

```
[difftool "sourcetree"]
cmd = 'C:\\Program Files\\Beyond Compare 4\\BComp.exe' \"$LOCAL\" \"$REMOTE\"
trustExitCode = true
```

Note the usage of **BComp.exe** and the **double backslash**.

In SourceTree -\> Options -\> Diff, under "External Diff / Merge, I used the calling to the same .exe file.


author: Terris Linenbach
body: This problem occurs on OSX (macos, mac) too. I'm using high sierra. The issue is \~/.gitconfig is not altered by SourceTree despite the Preferences/General setting, and this file is used even when using the embedded git.

I fixed the problem by modifying \~/.gitconfig for BeyondCompare per <https://www.scootersoftware.com/support.php?zz=kb_vcs_osx> :

\[diff\]

**tool** = bcomp

\[difftool\]

**prompt** = false

\[difftool "sourcetree"\]

**trustExitCode** = true

**cmd** = "/usr/local/bin/bcomp" \\"$LOCAL\\" \\"$REMOTE\\"

\[difftool "bcomp"\]

**trustExitCode** = true

**cmd** = "/usr/local/bin/bcomp" \\"$LOCAL\\" \\"$REMOTE\\"

\[merge\]

**tool** = bcomp

\[mergetool\]

**prompt** = false

\[mergetool "bcomp"\]

**trustExitCode** = true

**cmd** = "/usr/local/bin/bcomp" \\"$LOCAL\\" \\"$REMOTE\\" \\"$BASE\\" \\"$MERGED\\"

\[mergetool "soucetree"\]

**trustExitCode** = true

**cmd** = "/usr/local/bin/bcomp" \\"$LOCAL\\" \\"$REMOTE\\" \\"$BASE\\" \\"$MERGED\\"


Tags: external-diff