[pre-commit] Move codespell-log to post-commit
The current pre-commit hook codespell-log works with script
gdb/contrib/codespell-log.sh.
During the commit-msg phase of a commit, the following happens:
- git calls pre-commit
- pre-commit calls gdb/contrib/codespell-log.sh,
- gdb/contrib/codespell-log.sh calls pre-commit, and
- precommit calls codespell.
This purpose of this indirection is to:
- ignore the exit status of codespell (to make sure that the commit is not
aborted), and
- control the version of codespell.
However, if the check fails, the output is a bit messy due to the indirection:
...
$ touch gdb/bla.c
$ git add gdb/bla.c
$ git commit -m "Usuable"
...
codespell-log............................................................Passed
- hook id: codespell-log
- duration: 0.43s
codespell-log-internal...................................................Failed
- hook id: codespell
- exit code: 65
.git/COMMIT_EDITMSG:1: Usuable ==> Usable
[detached HEAD
18ec133830f] Usuable
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 gdb/bla.c
...
And if the check passes, the output is still verbose due to the verbose=true
setting.
I found a simpler way to implement this.
Given that we don't want to abort the commit, the post-commit stage is a more
natural place for this check. Moving it there solves two problems:
- we no longer need to ignore the exit status of codespell
- we no longer need the verbose=true setting
The only issue is that we need to generate the file containing the commit
message ourselves, something that is provided by git in the commit-msg stage.
So we still need a wrapper script.
However, it seems that specifying a shell script as entry point of a codespell
hook is fine, so we no longer need to call pre-commit from codespell-log.sh.
Having simplified codespell-log.sh, we can downgrade it to a /bin/sh script,
instead of requiring bash.
Checked with shellcheck.