I created a pre-commit script for git, which is working fine when run via command line. Here's that script:
#!/bin/sh
#
# Pre-commit hooks
echo "Running unit tests..."
# Lint stuff before commiting
grunt runtests
RESULT=$?
[ $RESULT -ne 0 ] && echo "Tests (or tasks) failed, aborting the commit" && exit 1
echo "All tests passed, commiting your changes" && exit 0
I'd would like the pre-commit to also work via the GitHub client application, but I can't get that working. The pre-commit script is executed, but it throws an error. Here's the full text it returns in the client alert window:
Running unit tests...
.git/hooks/pre-commit: line 7: grunt: command not found
Tests (or tasks) failed, aborting the commit
(1)
For some reason, it is not able to find grunt. I've reinstalled the grunt cli again and used the global '-g' flag, but that made no difference. Any ideas how I can get the client to find grunt?
GUI apps on OS X doesn't load the stuff in .bashrc/.bash_profile, which means they won't have user specified $PATH additions like /usr/local/bin
, which is where the grunt binary is. You can either specify the full path or fix the $PATH in your pre-commit hook, by adding this after the top comments: PATH="/usr/local/bin:$PATH"
If you are using sourcetree (on Mac) and you have pre-commit and pre-push hooks, open sourcetree with command line instead of opening it directly, with following command.
open /Applications/SourceTree.app/Contents/MacOS/SourceTree
Now your hooks will work when you try to commit and push. I am sure it work for github app as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With