Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git pre-commit hook failing in GitHub for mac (works on command line)

Tags:

I've created a very simple pre-commit script:-

#!/usr/bin/env sh  # Run tests npm test if [ $? -ne 0 ]; then   echo "Tests failed. Aborting.."   exit 1 fi  exit 0 

When I run git commit at the command line (with failing tests), I get the expected exit 1 with the message Tests failed. Aborting...

However, If I use GitHub for Mac however I get:

.git/hooks/pre-commit: line 5: npm: command not found Tests failed. Aborting..  (256) 

I'm guessing its down to npm not being available to the execution environment that GitHub for Mac is using, but I've been tearing my hair out trying to work out how to fix this.

like image 748
isNaN1247 Avatar asked Oct 14 '12 11:10

isNaN1247


1 Answers

Resolved. As globally installed node modules end up under /usr/local/bin I simply needed to add the following at the beginning of my pre-commit:

PATH=$PATH:/usr/local/bin:/usr/local/sbin 

i.e. appending both /usr/local/bin and /usr/local/sbin to PATH at the point of execution.

like image 187
isNaN1247 Avatar answered Oct 01 '22 18:10

isNaN1247