Skip to content
Stefano Maggiolo edited this page Dec 20, 2012 · 3 revisions

Git hooks

When you work on the CMS git repository, please install pep8 and pyflakes and add the following pre-commit hook:

#!/usr/bin/env bash

FILES=$(git diff --cached --name-status | awk '$1 $2 { print $2}' | grep -e \.py$)

if [ -n "$FILES" ]; then
    pep8 -r $FILES
    p8=$?
    pyflakes $FILES
    pf=$?
    if [ "$p8" != "0" -o "$pf" != "0" ]; then
        exit 1
    fi
fi

exit 0

You just have to write this content in .git/hooks/pre-commit and make it executable (chmod 755 .git/hooks/pre-commit). It does a few sanity checks in the files you're changing and warns you about potential errors and bad styles.

You're usually advised not to ignore these warnings. If you really want to do so (for example, for implementing them in a separate commit), pass the -n option to git commit.