Created
January 31, 2018 09:09
-
-
Save Gazzell/707c3ecfa86f03513da23fffef4ac713 to your computer and use it in GitHub Desktop.
pre-commit. Only commit if pass tests and there are not leftovers (.only and .skip)
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
branch=`git symbolic-ref HEAD` | |
if [ "$branch" = "refs/heads/master" ]; then | |
echo "Direct commits to the branch master are not allowed" | |
exit 1 | |
fi | |
testLeftOvers=`git diff --staged test/**/* | grep '^+' | grep '.only\|.skip'` | |
if [ -n "$testLeftOvers" ]; then | |
echo "You have leftovers in your tests, please remove them:" | |
echo $testLeftOvers | |
exit 1 | |
fi | |
echo "Stashing unstaged changes..." | |
git stash --keep-index -u | |
if npm test; then | |
git stash pop | |
echo "Putting unstaged changes back..." | |
else | |
git stash pop | |
echo "Putting unstaged changes back..." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment