gitx icon indicating copy to clipboard operation
gitx copied to clipboard

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

Open rjmunro opened this issue 10 years ago • 4 comments

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.

rjmunro avatar Feb 27 '15 15:02 rjmunro

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...

tiennou avatar Feb 27 '15 15:02 tiennou

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.

hardkrash avatar Mar 05 '15 20:03 hardkrash

@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.

rjmunro avatar Sep 25 '15 09:09 rjmunro

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!

bpartridge avatar Jul 01 '21 02:07 bpartridge