Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot source nvm.sh from git hook #301

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

Cannot source nvm.sh from git hook #301

knpwrs opened this issue Oct 6, 2013 · 3 comments

Comments

@knpwrs
Copy link

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
Copy link
Author

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 knpwrs closed this as completed Oct 9, 2013
@adriano-di-giovanni
Copy link

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.

@koenpunt
Copy link
Contributor

Try the nvm-exec.sh binary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants