Skip to content

Instantly share code, notes, and snippets.

@whilefalse
Created October 12, 2009 13:13
Show Gist options
  • Save whilefalse/208377 to your computer and use it in GitHub Desktop.
Save whilefalse/208377 to your computer and use it in GitHub Desktop.
A simple git pre-commit nosetest runner, with configurable test directories. Move to .git/hooks/pre-commit and make executable to enable.
#!/bin/bash
echo -e "======================================================================================\n"
echo " >>> Running pre-commit hook..."
dirs=`git-config --get tests.directories`
if [ -z "$dirs" ]
then
echo -e " >>> You have no tests.directories setting. Tests will not be run.\n >>> To enable tests on pre-commit run:\n\tgit config --add tests.directories <space separated list of test dirs>\n"
echo -e "======================================================================================\n"
exit 0
fi
echo -e " >>> Running tests ('nosetests $dirs')\n"
echo -e "======================================================================================\n"
nosetests $dirs
code=$?
echo -e "======================================================================================\n"
if [ "$code" != "0" ]
then
echo -e " >>> Tests failed. Commit aborted. To force the commit, run: \n\tgit commit --no-verify\n"
else
echo -e " >>> Tests passed. Committing...\n"
fi
echo -e "======================================================================================\n"
exit $code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment