Spell checking git commit messages turns out to be oddly hard.
The hook to do it in is
commit-msg but there are a few problems.
First is making global hooks and second is doing the checking.
One might argue that you can just do this in your editor, but I usually
-m flag on
git commit so no editor gets a whack at it.
Since that trick won’t really work, what are the other options?
To make global hooks, you can just do
git config --global core.hooksPath ~/.config/git/hooks but that
will override all hooks. Any repo specific hooks won’t be run.
Which is not what I want. So I made shim scripts like this for hook
scripts I’d use in a local repo - this is for
commit-msg script it turns out you can’t run any interactive
program. Luckily you can run aspell non-interactively, but this means
there need to be some utility programs. This is the global
commit-msg script I came up with:
Note that these aren’t bash scripts - for various reasons some systems
I work on don’t have bash or have it in different places. So it’s just
plain POSIX shell. And in spite of shellcheck’s concerns, every
modern POSIX shell I’ve used knows
The two utility programs mentioned in it -
git-spell-check - are, respectively, as follows:
So far it’s worked well. It’s caught a few typos and hasn’t been
too intrusive. Depending just on an error message and not hanging to
force me to do something is annoying. I’m going to need to get used to
git ci sometimes failing. But it would be nice not to have typos
locked in forever!