Skip to content

Instantly share code, notes, and snippets.

@stantonk
Created December 5, 2016 20:05
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 stantonk/09227e9f32984858cebf589f0387004d to your computer and use it in GitHub Desktop.
Save stantonk/09227e9f32984858cebf589f0387004d to your computer and use it in GitHub Desktop.
Run unittests as a pre-push hook to avoid merging code that fails tests.
#!/usr/bin/env bash
################################################################################
# Use as a global mercurial/git pre commit or pre push hook to detect the type
# of project and run unittests before allowing a commit or push to a remote
# repository.
#
# Handy so that you don't have to remember to add test running hooks to every
# repo clone/fork you have.
################################################################################
echo "run-test-hooks executing..."
cmd=""
if [ -e "pom.xml" ];
then
cmd="mvn clean -U test"
fi
if [ -e "manage.py" ];
then
cmd="python manage.py test"
fi
if [ -e "setup.py" ];
then
cmd="python -m unittest discover"
fi
$cmd
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment