Archive pour la catégorie ‘git’

Run Django tests automatically before committing on Git

Mercredi 16 février 2011

Since I often forget to run unit tests before committing, I spend a lot of time looking for the bad commit when I find regressions 3 commits later.

However it’s really easy to automatically run tests before each commit. In .git/hooks/pre-commit, put :

python test
exit $?

then chmod 755 this file and it’s done. I really love git :-)

Do not forget to source your virtualenv before committing.

Note that tests are run on your working tree and not the commit itself, so if you commit only a part of your working tree, it may fail while your commit passes tests.