Created
January 5, 2016 21:07
-
-
Save guicheffer/5a9211c3c82d363f18ae to your computer and use it in GitHub Desktop.
hook to force tests and prevent failing pushs to develop or master
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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