observing/pre-commit

Only run commit hook on master

Closed this issue · 3 comments

Is there a way to configure this to only run the commit hooks on master?

Is there a way to configure this to only run the commit hooks on master?

That seems like a really bad idea. You'll want to verify things as early as possible. By the time things get to master they should be clean.

I supposed this is related to #50, check out the script to only verify staged changes.

Yes, it was more because of the performance issue- the scripts taking so long to run. I think I'll make it so on master it forces to run on the whole repo, but outside of the branch, only on staged changes. I'll figure it out from here. Thanks again!

#!/bin/bash

git stash -q --keep-index

branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')

if [ "$branch" ==  "master" ]; then
    echo 'Commit on master: Running jshint on entire depo.'
    $(npm bin)/jshint .

else
    echo 'Commit on non-master branch: Running jshint on current changeset.'
    git diff-index --cached HEAD --name-only --diff-filter ACMR | egrep '.js$' | xargs $(npm bin)/jshint
fi

RESULT=$?

git stash pop -q

[ $RESULT -ne 0 ] && exit 1
exit 0

final script we went with for future googlers