nvm not found in git hook shell files

Created on 9 Mar 2015  路  2Comments  路  Source: nvm-sh/nvm

I've got a pre-commit git hook that bundles code for me, and my bundling process requires v0.12 at the moment as there's an issue with iojs one of my deps can't take. I've set my default using nvm alias default v0.12, but I think my system is still using iojs, because when I commit I get the error I would expect if I did. I think the issue is that but my git hook shell script can't seem to find nvm, and defaults to system.

I added these lines to the hook:

which node
nvm ls

And got:

$ sh .git/hooks/pre-commit
/Users/richard/.nvm/versions/node/v0.12.0/bin/node
.git/hooks/pre-commit: line 7: nvm: command not found

And now I am confused - why is nvm not found?

Most helpful comment

What kind of shell does the git hook execute with? If it's a non-interactive shell, it probably doesn't source nvm.sh. Try adding . $NVM_DIR/nvm.sh to your git hook. (it might be explicitly preserving your PATH but not the shell environment)

Also, what version of git are you using?

All 2 comments

What kind of shell does the git hook execute with? If it's a non-interactive shell, it probably doesn't source nvm.sh. Try adding . $NVM_DIR/nvm.sh to your git hook. (it might be explicitly preserving your PATH but not the shell environment)

Also, what version of git are you using?

That did it! I guess it's non-interactive.

Not relevant anymore, but:

$ git --version
git version 2.3.0
hub version 2.2.0-rc1-g1409606
Was this page helpful?
0 / 5 - 0 ratings