Hi! πŸ‘‹ I’m now looking for my next role,
and you can read more about that here.

Nik Kantar

Friday, October 16, 2020
2 min read

Introducing Autohook

I made a little Git hook manager and some people even use it!

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:

β”œβ”€β”€ .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.

Introducing sus
Hire Me! (v.2020.10)