Using git pre-commit hooks in context of GitHub client Using git pre-commit hooks in context of GitHub client unix unix

Using git pre-commit hooks in context of GitHub client


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 want to run a script that gets your environment ($PATH, etc) you should change the first line of your script from this:

#!/bin/sh

to:

#!/usr/bin/env sh

Then call grunt without the hard coded path.

This way if the path to your executable changes in the future or is different on other machines the script will still work. /usr/bin/env will get the environment of the user that the script is running as. This is really helpful in places where some people use different package managers but need to run the same scripts. Otherwise you could end up with a lot of logic looking for applications that could've been avoided by depending on a properly populated $PATH.