51

I regularly use Atlassian SourceTree (on Mac OS X) to launch FileMerge to resolve git merge conflicts. Out of the blue it has stopped working: when I right click and select Resolve Conflicts > Launch External Merge Tool, FileMerge launches, creates its intermediate files, then immediately exits. SourceTree interprets that as the merge process being complete.

What's the issue and how can I debug/fix it?

I note that a previous question 'SourceTree filemerge quits immediately and creates 4 files. How to fix it?' does not address this particular scenario (for one, it says FileMerge quits in the title, but in the body it says FileMerge displays /dev/null as one of the panels. Additionally, my merge conflict is not due to a removed file.)

Community
  • 1
  • 1
Greg Kopff
  • 14,301
  • 10
  • 49
  • 67

5 Answers5

157

To diagnose the problem, I ran opendiff from the Terminal. I received the following error:

xcode-select: error: tool 'opendiff' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

To solve:

  1. Open Xcode > Preferences > Locations
  2. Click on the drop-down box beside Command Line Tools and select your current Xcode version. (This was empty for me because I had recently installed Xcode on a new Mac.)

Command Line Tools

  1. Run opendiff in Terminal again, and the above error should no longer appear.

Now FileMerge will open correctly from SourceTree when you click Launch External Merge Tool.

ChrisJF
  • 6,032
  • 4
  • 31
  • 36
  • 1
    Thanks, fixed the issue, It is still SourceTree's bug not to alert on the error, and to consider the file "merged" though. However, this Mac application is so bad - I don't even care to notify them about their bugs anymore. Nothing to expect there. – Motti Shneor Jan 03 '19 at 09:32
  • @MottiShneor I agree that SourceTree should improve their user experience. This [bug is already filed](https://jira.atlassian.com/browse/SRCTREE-3644) so feel free to up-vote it. – ChrisJF Jan 04 '19 at 13:39
  • Thanks for the answer, it fixed my problem. It is unfortunate that SourceTree doesn't show any error dialog about this. – Balázs Gerlei May 03 '19 at 08:56
  • This fixes opendiff ( FileMerge ) not opening from SourceTree when selecting Resolve Merge Conflicts using External Tool – jcpennypincher May 04 '19 at 03:11
  • Fixed mine too for Tower. My Xcode was not recently installed, but gets updated automatically and one of those updates left the Command Line Tools location empty. Had to quit both apps and then re-start Xcode and Tower (in that order). – Elise van Looij May 24 '19 at 14:36
  • Thanks, you saved me. fixed my issue. – EnasAZ Dec 01 '19 at 16:21
  • I love Stack Overflow. I was scouring the fork.io release notes looking for something on this. I forgot the golden rule: XCode is always the problem. – gyleg5 Feb 06 '20 at 21:45
  • You have saved my life! – Morgan Koh Dec 11 '20 at 15:41
16

For me, SourceTree didn't even launch FileMerge. When clicking Launch External Merge Tool nothing happened.

Moreover, running opendiff in Terminal worked as expected:

$ opendiff
opendiff[64176:5561154] too few arguments
opendiff[64176:5561154] usage: opendiff file1 file2 [-ancestor ancestorFile] [-merge mergeFile]

What helped me was manually configuring SourceTree to use FileMerge via the opendiff command with the following arguments: $LOCAL $REMOTE -ancestor $BASE -merge $MERGED

SourceTree manually configure to use opendiff

This way, SourceTree opens FileMerge as expected.

Tom Kraina
  • 3,159
  • 1
  • 31
  • 53
  • 2
    Same here, but i don't know why it didn't work when just set to file merge – MegaManX Jan 24 '18 at 09:32
  • yup, this did it for me, finally, after a lot of trial and errors. If I just select diffmerge from the dropdown, it fails to launch external diff tool (ST shows a window saying that will need to close diff tool to return, but that window closes imediately). diffmerge was set correcly in .gitconfig, worked fine with "git mergetool" command, but I guess ST was ignoring that altogether – Radu Simionescu Sep 26 '19 at 17:14
  • I've had perpetual issues with this for many years. It has always been resolved by ensuring I agreed to the license agreement for xcode developer tools...until now. Your solution seems to do the trick this time. However, it did not work at first; I had to nuke my ~/.gitconfig file for some reason. – mrclary Feb 24 '20 at 21:00
  • Update: It seems that the "FileMerge" selection in ST now works again. Perhaps I just needed to nuke my config file. – mrclary Feb 24 '20 at 21:16
12

This helped: https://gist.github.com/kylefox/4512777

Tell system when Xcode utilities live:

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

Set "opendiff" as the default mergetool globally:

git config --global merge.tool opendiff

user3027622
  • 141
  • 1
  • 4
8

If Xcode has recently updated itself, you may need to agree to the new license terms. If you have not agreed to the license terms, FileMerge (when launched from SourceTree) will quit immediately.

To check for this, open a shell and run as your usual user:

$ opendiff

If the license is the problem, it will tell you. To agree to the new license terms, you'll need to run open diff using sudo:

$ sudo opendiff

After agreeing to the license terms, you can now retry launching FileMerge from SourceTree using Resolve Conflicts > Launch External Merge Tool. FileMerge should launch and behave normally.

Greg Kopff
  • 14,301
  • 10
  • 49
  • 67
  • 3
    It says `opendiff xcode-select: error: tool 'opendiff' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance` – KarenAnne Dec 20 '15 at 11:04
  • @Greg Kopff's thanks, your solution worked with me! :) In my case SourceTree was not openning FileMerge. I did update Xcode to 10.2.1 recently but I was using a previous active developer directory (see "xcode-select" terminal command) for still compiling some projects with Xcode 10.1 compiler. After setting the correct active developer directory again, "opendiff" runned ok and SourceTree was able again to open FileMerge. – Ricardo Barroso May 17 '19 at 10:33
4

This also works to resolve the message "xcode-select: error: tool 'opendiff' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance":

sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
fabe
  • 416
  • 3
  • 6