Note: Autohook isnβt new at allβthe first release was published on January 31st, 2017, and the most recent on August 26th, 2018. I just never wrote a proper introduction post about it, and given its popularityβ92 stargazers, some users, and even 4 co-maintainersβit certainly feels warranted.
Way, way back in early 2017, I wanted to implement some Git hooks in a repository at SimpleLegal. Being my usual self, I decided to both overengineer the solution and not use any existing tooling, because that would be entirely too sensible.
So I wrote a relatively simple tool to automagically run Git hooks that can be added to
the repo itself.
Itβs basically a simple shell script that replaces the various hook files in
.git/hooks/
and then looks for scripts to run in appropriately named directories in
hooks/
.
An example tree is probably clearer than my description:
my_project/
βββ .git/
β βββ post-checkout # symlink to hooks/autohook.sh
β βββ pre-commit # symlink to hooks/autohook.sh
β βββ ... # other symlinks to hooks/autohook.sh
βββ hooks/
β βββ autohook.sh
β βββ post-checkout/
β β βββ 01-delete-pyc-files # symlink to hooks/scripts/delete-pyc-files.sh
β βββ pre-commit/
β β βββ 01-delete-pyc-files # symlink to hooks/scripts/delete-pyc-files.sh
β β βββ 02-run-tests # symlink to hooks/scripts/run-tests.sh
β βββ scripts/
β βββ delete-pyc-files.sh
β βββ run-tests.sh
βββ ...
Why did I do it this way? Well, I wanted to be able to enforce the running of said scripts across the team. Furthermore, I didnβt really give other existing solutions (e.g., pre-commit) an honest look, likely because I wanted to do it myself. That said, I vaguely remember not quickly finding anything that didnβt have to be installed on a POSIX system, and Autohook was always intended to be just a portable shell script with no dependencies other than a compatible shell.
Anyway, now itβs gaining a bit of a life of its own. I havenβt used it in years, but others still seem to, so Iβve moved it to a GitHub organization. Itβll likely get more love than it has from me in quite a while.
And now you know about it too! :)
Thanks for reading! You can keep up with my writing via the feed or newsletter, or you can get in touch via email or Mastodon.