rowanj / gitx

Fork of Pieter's nice git GUI for OS X. Includes branch/tag sidebar and various fixes. Current development focus is on removing legacy git command line usage in favour of libgit2 and objective-git.
http://rowanj.github.com/gitx
Other
2.15k stars 204 forks source link

git hook fails because $PATH isn't defined when it runs #433

Open rjmunro opened 9 years ago

rjmunro commented 9 years ago

Is there a way to specify the environment variables that hooks will be executed with? I have a hook that uses nodejs that is installed at /usr/local/bin/node, but the hook says the command node cannot be found. I have worked around it by manually adding a line:

export PATH=$PATH:/usr/local/bin

at the top of the bash hook script itself.

tiennou commented 9 years ago

Not really. Also, I'm not sure it's in GitX scope to have that kind of customizability, because as far as I know, libgit2 won't support hooks in the traditional "shell script" sense.

Have you tried using #!/usr/bin/env bash as your shebang line ? But I think you might lose git-specific environment variables though...

hardkrash commented 9 years ago

Are you sure you have your bash environment set up properly?

.bashrc vs .bash_profile

http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html The git hooks are not running in an interactive shell.

rjmunro commented 9 years ago

@hardkrash My bash environment is set up correctly, yes. The problem is that bash never runs if I log in to my Mac and start gitx from the GUI. This seems like the same problem atom has here: https://github.com/atom-community/linter/issues/726

The solution should be to put paths in /etc/paths and /etc/paths.d/ rather than configuring bash profiles etc., but those paths are not making it to gitx in my setup.

bpartridge commented 3 years ago

For anyone else coming across this, fully closing gitx and relaunching it from the terminal with gitx . while your PATH is set properly (e.g. to a virtualenv) seems to cause it to inherit that environment, letting pre-commit hooks run as they would if git were called from the command line!