Wolfgang Fellger | Using SVN's hooks for styleguide checking

Using SVN's hooks for styleguide checking

Keeping your code strictly according to styleguide can be a time-consuming task, especially when working in a team. So I thought at least part of the proofreading could be automated - by using SVN hooks.

SVN hooks

A 'hook' is basically a script that is executed on a certain event and may manipulate or, depending on its return value, stop the current transaction. The hook we're looking for here is 'pre-commit'. SVN will then automatically refuse to check in code that is not conforming to style guide.
Unfortunately, all a hook gets is a transaction number, so before validation can take place the necessary data (file names etc.) need to be collected.

Since I'm a lazy guy, I basically ripped off this example hook, which does all the boring work, and plugged in a new python module 'stylecheck'.

What it can do so far

(Note that this is specifically created for matching Ada source files against our programming course's styleguide, but may of course be adopted for other purposes)


pre-commit (SVN hook)

Just copy both files into your repository's 'hooks' directory and set rights to 550.