I’m currently available for hire.
You can read more about it here, head directly to my résumé, or email me.

Nik Kantar

Friday, October 16, 2020

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:

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! :)