Using git pre-commit hooks to keep your Drupal codebase clean

All too often when peer reviewing code done by other Drupalers, I spot debug code left in the commit, waiting for the chance to be deployed to staging and break everything.

I started to read up on git hooks, paying particular attention to pre-commit:

This hook is invoked by git commit, and can be bypassed with --no-verify option. It takes no parameter, and is invoked before obtaining the proposed commit log message and making a commit. Exiting with non-zero status from this script causes the git committo abort.

You can write you pre-commit hook in any language, bash seems the most sane due to the power of text analysis tools at your disposal.