vscode icon indicating copy to clipboard operation
vscode copied to clipboard

VSCode 1.1.0 doesn't recognize Git installed on OS X

Open natewallace opened this issue 10 years ago • 11 comments

  • VSCode Version: 1.1.0
  • OS Version: OS X Yosemite (10.10)

Steps to Reproduce:

  1. Have Git version 2.6.2 installed.
  2. Open VSCode
  3. Display the Git view in VSCode and notice that it says 'It looks like git is not installed on your system.'

The Git integration was working for quite a while until I upgraded VSCode to version 1.1.0.

natewallace avatar May 10 '16 18:05 natewallace

This issue seems to be intermittent for me. It appears that vscode recognizes git installed sometimes and sometimes it doesn't. When it is working it seems to work up until I restart my machine and then it may or may not work the next time I start up.

Sorry I can't give more specific details.

natewallace avatar May 13 '16 12:05 natewallace

If you open a Terminal, what do you get with the following commands?

which git
echo $PATH

Does it make a difference if you launch it with a double click in FInder or via the command line with code?

joaomoreno avatar May 24 '16 08:05 joaomoreno

which git = /usr/local/bin/git echo $PATH = /usr/local/bin:/usr/bin:/usr/sbin:/sbin

I tend to always open vscode using the command line via an automator script. Just now I started vscode using finder and it worked. I then tried it via the automator script and it didn't work. I then tried it using the command line directly and it worked. I then tried via the automator script again and it worked.

My automator script is simply a bash shell with the following: /usr/local/bin/code $@

natewallace avatar May 24 '16 12:05 natewallace

This is very odd. No idea what is going on there... If you open it several times successfully with the Automator script, the reproducibility is random?

joaomoreno avatar May 24 '16 12:05 joaomoreno

It seems random at initial start up. If it's working the first time I launch the app it tends to stay working until I shut down my computer. The reverse is true as well. If it's not working at initial start up then it tends not to work up until I shut down my computer.

natewallace avatar May 24 '16 12:05 natewallace

I was able figure out how to use the debug tools to trace through the code and I think I understand what is going on.

It looks like my problem is in the following section of code: https://github.com/Microsoft/vscode/blob/889fe706989a52613d5698c72252a4e1a0f67b0d/src/vs/workbench/parts/git/electron-browser/electronGitService.ts#L47-L84

I tested opening vscode using my automator script and for some reason the which git command run by vscode is getting the value /usr/bin/git which is different from the value I get when running the same command in a terminal.

Because of the value returned from the which git command the xcode-select -p command gets run by vscode. On my machine this results in the following error which has an error code of 2:

xcode-select: error: unable to get active developer directory, use `xcode-select --switch` to set one (or see `man xcode-select`)

Because the xcode-select -p command failed it returns the git not found error even though the failure appears to be unrelated to the presence of git.

I'm guessing I can work around this by making changes in either my automator script or in the xcode configuration on my machine.

natewallace avatar May 24 '16 14:05 natewallace

Good catch. That still doesn't explain why it works sometimes though...

Also, what do you get when running $SHELL -ilc env? We run this on startup to get the correct environment in Code, which should make it pick up /usr/local/bin/git as the right git to use.

joaomoreno avatar May 24 '16 14:05 joaomoreno

I get the following from my terminal after running the command:

TERM_PROGRAM=Apple_Terminal
TERM=xterm-256color
SHELL=/bin/bash
TMPDIR=/var/folders/nt/dpqjbhc10jj3sc0_qcrdz1v80000gn/T/
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.IHMWKWftqG/Render
TERM_PROGRAM_VERSION=343
TERM_SESSION_ID=C2E458F3-510E-4E3D-A8F6-0C34F6D13B51
USER=natewallace
http_proxy=http://10.215.109.16:8080/
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.6q4G4QCEXe/Listeners
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
PWD=/Users/natewallace
LANG=en_US.UTF-8
XPC_FLAGS=0x0
https_proxy=http://10.215.109.16:8080/
XPC_SERVICE_NAME=0
HOME=/Users/natewallace
SHLVL=2
no_proxy=localhost,*.local
LOGNAME=natewallace
_=/usr/bin/env

I get the following when running the command using the exec function within a running instance of vscode that doesn't recognize git being installed:

VSCODE_CLI=1
SHELL=/bin/bash
TMPDIR=/var/folders/nt/dpqjbhc10jj3sc0_qcrdz1v80000gn/T/
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.IHMWKWftqG/Render
http_proxy=http://10.215.109.16:8080/
USER=natewallace
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.6q4G4QCEXe/Listeners
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
GOOGLE_API_KEY=AIzaSyAQfxPJiounkhOjODEO5ZieffeBv6yft2Q
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
PWD=/Users/natewallace
ELECTRON_NO_ATTACH_CONSOLE=1
XPC_FLAGS=0x0
https_proxy=http://10.215.109.16:8080/
XPC_SERVICE_NAME=0
HOME=/Users/natewallace
SHLVL=4
VSCODE_NLS_CONFIG={"locale":"en-us","availableLanguages":{}}
no_proxy=localhost,*.local
VSCODE_SHARED_IPC_HOOK=/var/folders/nt/dpqjbhc10jj3sc0_qcrdz1v80000gn/T/Code-e5f2ec-shared.sock
LOGNAME=natewallace
VSCODE_IPC_HOOK=/var/folders/nt/dpqjbhc10jj3sc0_qcrdz1v80000gn/T/Code-e5f2ec.sock
VSCODE_PID=1663
_=/usr/bin/env

natewallace avatar May 24 '16 16:05 natewallace

Ok, no real difference in the PATH variable there.

It's like xcode-select sometimes fails and sometimes succeeds...

There are two possible workarounds here:

joaomoreno avatar May 25 '16 06:05 joaomoreno

Actually I'm guessing it's the value that's returned from the which git command that is varied for some reason. I just stepped through the code while it's working and the which git command is returning /usr/local/bin/git as expected which bypasses the call to xcode-select -p.

I'm guessing that for some reason the path isn't always correct when the automator script runs. I've added a command to my automator script to set the PATH variable every time it runs which seems to have resolved the issue from what I can tell. Here is what my script looks like now:

export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
/usr/local/bin/code "$@"

natewallace avatar May 25 '16 12:05 natewallace

Alright, good to know. I will close it since it seems this is very specific to your system.

joaomoreno avatar May 25 '16 16:05 joaomoreno