Skip to content

Instantly share code, notes, and snippets.

@guicheffer
Created January 5, 2016 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guicheffer/5a9211c3c82d363f18ae to your computer and use it in GitHub Desktop.
Save guicheffer/5a9211c3c82d363f18ae to your computer and use it in GitHub Desktop.
hook to force tests and prevent failing pushs to develop or master
#!/usr/bin/env bash
# .git/hooks/pre-push
# hook to force tests and prevent failing pushs to develop or master
#
# Refs:
# http://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
# http://blog.ittybittyapps.com/blog/2013/09/03/git-pre-push/
#
# Bypassing the pre-push hook:
# git push --no-verify
TEST_BACK="py.test tests/unit" # Command that runs your tests
TEST_FRONT="grunt test" # Command that runs your tests
# Check if we actually have commits to push
commits=`git log @{u}..`
if [ -z "$commits" ]; then
exit 0
fi
current_branch=$(git rev-parse --abbrev-ref HEAD)
if [[ $current_branch = 'develop' || $current_branch = 'master' ]]; then
$TEST_FRONT
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo "Not pushing, failed test: \"$TEST_FRONT\""
exit 1
fi
$TEST_BACK
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo "Not pushing, failed test: \"$TEST_BACK\""
exit 1
fi
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment