Skip to content

Instantly share code, notes, and snippets.

@stantonk
Last active August 29, 2015 14:23
Show Gist options
  • Save stantonk/9674ee8899dae1ef46a3 to your computer and use it in GitHub Desktop.
Save stantonk/9674ee8899dae1ef46a3 to your computer and use it in GitHub Desktop.
In a mercurial or git pre-commit or pre-push hook: detect the type of project and invoke the appropriate test runner for various projects. So far Maven and Django projects are supported. Trivial to add others. No-ops on unknown project types.
#!/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.
#
# ********** MERCURIAL SETUP *************
# in your global ~/.hgrc:
# --- SNIP ---
# [hooks]
# pre-push.runtestshooks = ~/run-tests-hook.sh
# --- SNIP ---
#
# ********** GIT SETUP *************
# TODO!
################################################################################
cmd=""
if [ -e "pom.xml" ];
then
cmd="mvn clean -U test"
fi
if [ -e "manage.py" ];
then
cmd="python manage.py test"
fi
# TODO add more...
$cmd
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment