Created
November 19, 2017 17:12
-
-
Save watsy0007/2809168344337e2b80262ecdc202fb70 to your computer and use it in GitHub Desktop.
pre commit rails test
This file contains hidden or 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
#!/bin/bash | |
STASH_NAME="pre-commit-$(date +%s)" | |
git stash save -q --keep-index $STASH_NAME | |
cd backend | |
ERROR_MSG=`rails test | grep "errors,"` | |
cd - | |
TASHES=$(git stash list) | |
if [[ $STASHES == "$STASH_NAME" ]]; then | |
git stash pop -q | |
fi | |
ERR_NUM=`echo $ERROR_MSG | awk {'print $7'}` | |
FAIL_NUM=`echo $ERROR_MSG | awk {'print $5'}` | |
if [ $FAIL_NUM -ne 0 ] | |
then | |
echo -e "Can't commit! You've broken fails $FAIL_NUM tests!!!" | |
exit 1 | |
else | |
if [ $ERR_NUM -ne 0 ] | |
then | |
echo -e "Can't commit! You've broken errors $ERR_NUM tests!!!" | |
exit 1 | |
fi | |
fi | |
echo -e "All tests passed. You didn't broke anything. Congrats!\n" | |
exit 0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment