Skip to content

Instantly share code, notes, and snippets.

@guicheffer guicheffer/pre-push
Created Jan 5, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.