]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
[pre-commit] Move codespell-log to post-commit
authorTom de Vries <tdevries@suse.de>
Mon, 15 Dec 2025 16:19:26 +0000 (17:19 +0100)
committerTom de Vries <tdevries@suse.de>
Mon, 15 Dec 2025 16:19:26 +0000 (17:19 +0100)
commit7acd390ffd97070eaed468c6e21c2f1bcf5b8820
tree8cab599275664c752ef79183515272c561758706
parent255a9c42709958d0925d1d0d1d39d262972fd2a6
[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.
.pre-commit-config.yaml
gdb/contrib/codespell-log.sh