Use git-hooks to make sure you never check in ugly code again

The git-hooks project provides a way to run git hooks locally before you check in your code. This is especially useful if your code is hosted on GitHub because you don’t have access to install server side hooks.

From the README:

Hooks can be very powerful and useful. Some common hooks include:

  • Spell check the commit message.
  • Check that the code builds.
  • Verify that any new files contain a copyright with the current year in it.

Hooks can be very project specific such as:

  • Verify that the project still builds
  • Verify that autotests matching the modified files still pass with no errors.
  • Pre-populate the commit message with the ‘standard’ format.
  • Verify that any new code follows the ‘standard’ coding style.

or very specific to one person such as:

  • Don’t allow a push to a remote repository after 1am in case I break something and will be asleep.
  • Don’t let me commit between 9-5 for projects in ~/personal/ as I shouldn’t be working on them during work hours.

I wrote some hooks for checking PHP syntax and checking Python files using PEP-8 and PyFlakes.

Hopefully they’ll integrate this functionality into the git core at some point.