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
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! :)
If you want to chat about the above for any reason, the best ways to do so are probably email and Twitter. If you’d like to be notified when I post, you can subscribe to my newsletter. I promise I won’t spam you or sell your email address.