Hooked on hooks

Standard

I’ve been pretty impressed with what modern source version controls systems are able to do ever since Bryan Ward introduced me to git. (“Introduced me to git” is not strong enough, it’s more like “forced me to use git” and I couldn’t be more grateful to him for that!)

Among the many features of git that I love, one that it has in common with Mercurial, is the ability to customize hooks. One can define shell scripts that are executed when certain events happen. Bryan set one of these up to generate HTML pages from documentation in RST files we had for a project. Every time we pushed to the project’s git repo, the hook would run the command to update the HTML pages and our online documentation was always up to date.

Obviously, hooks can be used for much more than that. One use that I like a lot is running tests on code before you commit. This can protect programmers from poisoning the code base (or looking less than smart to their colleagues). Another one is to set up email notification to a group of people every time there’s new commit. All in all, this business of hooks is a great idea that can address a number of interesting issues.

More on the specifics of setting up git hooks are available here.