1. beno
  2. python-sword2


Clone wiki

python-sword2 / PrecommitHook

Functional Tests - a precommit hook

There is a simple script with in the repository's '.hooks' directory which will run nose against the functional tests and will throw an error if you try to commit the repository in a broken state.

If you are doing TDD, the script does give an option to ignore the pre-commit check if it fails so you can commit anyway.

Adding the Hook

Add the following to ".hg/hgrc" in your copy of the repository

precommit.RunFunctionalTests = .hooks/precommit.sh

Git compatibility

Just as an FYI, this code will also work with a Git repository - link the script to the following target:


Example code

In .hooks/precommit.sh (should already be in the repo if you clone it):

nosetests tests/functional

if [ "$code" == "0" ]; then
    exit 0

echo -n "Not all tests pass. Commit (y/n): "
read response
if [ "$response" == "y" ]; then
    exit 0

exit $code