Cannot source nvm.sh from git hook #301

Closed
knpwrs opened this Issue Oct 6, 2013 · 3 comments

Comments

Projects
None yet
3 participants

knpwrs commented Oct 6, 2013

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

. ~/.nvm/nvm.sh
echo $PATH

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

remote: hooks/post-receive: 19: /home/kpowers/.nvm/nvm.sh: Bad substitution
remote: hooks/post-receive: 79: /home/kpowers/.nvm/nvm.sh: [[: not found
remote: hooks/post-receive: 79: /home/kpowers/.nvm/nvm.sh: [[: 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/nvm.sh: [[: 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/nvm.sh and . ~/.nvm/nvm.sh 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/nvm.sh so the script fails and environment variables are not exported, even if you run . ~/.nvm/nvm.sh

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

Maybe you can find my gist useful.

Contributor

koenpunt commented May 23, 2014

Try the nvm-exec.sh binary

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