Qafoo GmbH - passion for software quality

Help you and your team benefit from new perspectives on cutting-edge quality engineering techniques and tools through the Qafoo team weblog.

By Kore Nordmann, first published at Tue, 20 Jul 2010 08:54:54 +0200

Presenting: PHP Commit Hooks

For those of us using SVN there are some quite common pre- and post-commit hooks in a lot of company repositories, all using their own implementation: Lint checks, CodeSniffer checks, etc. We created a small framework for those commit hooks, which makes it easy to create own checks and custom reporters.

For Continuous Integration see Arbit and PhpUnderControl - Qafoo provides professional support for both.

Beside the Continuous Integration system, which provides information for the full project it can be useful to report errors directly after a commit, only for the files which were affected by the commit. Additionally it can make sense to stop commits, which would break the build (for example because of parse errors).

SVN provides commit hooks, where you can hook into the commit process and intercept it. The pre-commit hooks allow to call scripts before the change is comitted to the repository, and thus aborting the change and report errors back to the comitter. Post-commit hooks are executed after the transaction and may be used to asynchronously report errors back to the commiter, which are not important enough to stop the user from comitting.

Classic examples for pre-commit hooks are to check the changed files for parse errors, or even if there are serious coding style violations and abort the commit with an error message in this case.

Coding style violations may also be checked in a post-commit hook, for example, so that the comitter will receive a list of violations in the files he just edited. This is more visible then the CS violations of the full project in the CI tool (which easily might be hundreds of thousands in some projects). Seeing only the violations in the just comitted files, it is easier for the user to just fix those and leave all changed files cleaned up.

PHP Commit Hooks

HTML commit mailHTML commit mail

To make creating such commit hooks trivial, we created PHP Commit Hooks which implements those common commit hooks and makes it easy to configure them.

The framework basically knows checks and reporters. The checks perform actions like lint checks or scanning for CS errors, while the reporters report those changes back to the user. For more details read the README on github.

PHP Commit Hooks also implements sending commit mails, so that you normally only need them installed as a singular commit hooks, which makes maintaining commit hooks easier.

The project is licensed under New BSD license and is available on Github for forking. Remember to call make init after the checkout to fetch its dependencies.

Get Technical Insights With Our Newsletter

Stay up to date with regular new technological insights by subscribing to our newsletter. We will send you articles to improve your developments skills.


  • Goran Miskovic on Tue, 20 Jul 2010 13:18:53 +0200

    Awesome work guys!

    Not that I am against The Python, on contrary The Pythons are my favorite comedians, but I like The PHP more. ;)