Skip to content

Instantly share code, notes, and snippets.

@FerPerales
Last active December 18, 2015 11:19
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 FerPerales/5774960 to your computer and use it in GitHub Desktop.
Save FerPerales/5774960 to your computer and use it in GitHub Desktop.
pre-push
#!/bin/sh
# This pre-push hook will run 'rake' command to check if your test
# suite passes by looking for ', 0 failures' in the 'rake' output
# If found, will return exit and the git push command will continue
# Make sure you remove the .sh extension and put the hook into your
# .git/hooks directory in your project
# --------------------------------------------------------------------
#!/bin/sh
SUCESS_OUTPUT="\, 0 failures"
echo "This script will run 'rake' command to make sure your test suite passes before pushing"
echo "You can skip this script by adding '--no-verify' to your regular 'git push [repository] [branch]' command"
echo 'This can take a while...'
exec 5>&1
OUTPUT=$( rake |tee /dev/fd/5)
if echo "$OUTPUT" | grep -q "$SUCESS_OUTPUT"; then
echo 'Test passed! proceeding with the push'
exit
else
echo "Some test did not pass! Failed test are shown above. Push aborted!"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment