Git hooks are a useful tool: they’re great for automating checking up behind yourself. There are already some great hook managers out there, such as Overcommit. I like what they do, but I have some disagreements with the various technical details of their approaches.
Over the past couple of weeks I built Quickhook. It’s a hook runner designed to be fast, self-contained, and Unix’y. Hooks are just programs in the hook directory. Quickhook manages running those programs, collecting exit codes and outputs, and reporting that to Git.
As an example, the pre-commit hook output in the Quickhook repository looks like:
$ git commit -m "Make directory existence check more precise"
[master 910179f] Make directory existence check more precise
2 files changed, 14 insertions(+), 11 deletions(-)
But if you try to commit some code that fails the
go vet check it will report the failure. It also exits with a non-zero exit code, which stops Git from proceeding with the commit.
$ git commit -m "Some incorrect code"
context/context.go:97: unreachable code
.git/hooks/pre-commit script is a call to
quickhook hook pre-commit. Go check it out on GitHub! You can easily install it via a Homebrew tap.