Skip to content

Instantly share code, notes, and snippets.

@Gazzell
Created January 31, 2018 09:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gazzell/707c3ecfa86f03513da23fffef4ac713 to your computer and use it in GitHub Desktop.
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)
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