Skip to content

Instantly share code, notes, and snippets.

@watsy0007
Created November 19, 2017 17:12
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 watsy0007/2809168344337e2b80262ecdc202fb70 to your computer and use it in GitHub Desktop.
Save watsy0007/2809168344337e2b80262ecdc202fb70 to your computer and use it in GitHub Desktop.
pre commit rails test
#!/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