Saturday, June 19, 2010

Managing project, user, and global git hooks

I recently put up a new tool on GitHub called git-hooks. This is a tool to manage project, user and global Git hooks for multiple git repositories.

Hooks can be very powerful and useful (as I have previously written about in my git hooks blog post). Some common hooks that I always want running no matter what git repository I am commiting to include:

- Spell check the commit message.
- Verify that any new files contain a copyright with the current year in it.

Every project also has specific hooks that I run 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.

And I have some hooks that are very specific to just me 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.

In the past I have just been copying these from one git repository to another, making symlinks or other nasty hacks. I finally sat down and wrote a tool to manage these different hooks.

After running 'git hooks --install' in a repository rather then using what is in .git/hooks the following locations will be checked for hooks:

- User hooks that are installed in ~/.git_hooks/
- Project hooks that are installed in the git_hooks directory inside of each project.
- Global hooks that are specified with the configuration.

If you have many hooks you don't have to write a wrapper to call them all, they all simply go inside of a directory (such as git_hooks/pre-commit/

git-hooks/contrib also includes various simple hooks I are useful that you might like to use. git-hooks is released under the BSD license.


jelford said...

What's the status of this project in relation to ? Is the intention to move development over to there, or is it just a fork?

Benjamin Meyer said...

@jelford, just a fork.

Popular Posts