Cannot source from git hook #301

knpwrs opened this Issue Oct 6, 2013 · 3 comments


None yet
3 participants

knpwrs commented Oct 6, 2013

I have the following in a git post-receive hook:

. ~/.nvm/
echo $PATH

When I push to the repo, the I get the following output:

remote: hooks/post-receive: 19: /home/kpowers/.nvm/ Bad substitution
remote: hooks/post-receive: 79: /home/kpowers/.nvm/ [[: not found
remote: hooks/post-receive: 79: /home/kpowers/.nvm/ [[: not found
remote: /usr/lib/git-core:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
remote: hooks/post-receive: 133: /home/kpowers/.nvm/ [[: not found
remote: -e 
remote:        N/A

I have also tried source instead of . which results in the following output:

remote: hooks/post-receive: 1: hooks/post-receive: source: not found
remote: /usr/lib/git-core:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

Running source ~/.nvm/ and . ~/.nvm/ work as expected.

knpwrs commented Oct 9, 2013

Moving the contents of post-receive to an executable file (in my case /home/kpowers/git/repo1/load) and changing the contents of /home/kpowers/git/repo1/hooks/post-receive to zsh ./load appears to work as a work-around.

knpwrs closed this Oct 9, 2013

I've just encountered same problem.

I've read nvm script's code and found that if NVM_DIR is not provided then script tries to get it from BASH_SOURCE.

BASH_SOURCE's value is not ~/.nvm/ so the script fails and environment variables are not exported, even if you run . ~/.nvm/

In order to successfully use nvm in a post-receive hook, you have to export NVM_DIR variable before running . ~/.nvm/

Maybe you can find my gist useful.


koenpunt commented May 23, 2014

Try the binary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment