[PATCH] [pre-commit] Fix codespell-log hook

Tom de Vries <[email protected]>
Newsgroups gmane.comp.gdb.patches
Message-ID <[email protected]>
A recent commit added this top-level setting to .pre-commit-config.yaml:
...
files: '^(gdb|gdbserver|gdbsupport)/'
...

This broke the codespell-log hook, which is a commit-msg hook, which is called
with the commit message as first argument.

However, the top-level files setting filters out .git/COMMIT_EDITMSG, with the
consequence that the commit-msg hook is no longer called.

It seems obvious to me that this is a pre-commit bug: the files field is there
to filter files in the repository, which .git/COMMIT_EDITMSG is not one of.
But upstream disagrees [1].

Use the workaround suggested as fix upstream: include .git/COMMIT_EDITMSG in
the default files set.

[ FWIW, that still doesn't fix something like this:
...
$ tmp=$(mktemp)
$ echo 'msg' > $tmp
$ pre-commit run --hook-stage commit-msg --commit-msg-filename $tmp
...

I wanted to mention that upstream, but I couldn't because I was already locked
out of commenting on the issue I filed. ]

Alternatively, we can drop the top-level files setting, and revert to
per-hook settings.

[1] https://github.com/pre-commit/pre-commit/issues/3720
---
 .pre-commit-config.yaml | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 2f86a333ab5..fda10e30b1d 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -40,7 +40,9 @@
 minimum_pre_commit_version: 4.5.1
 default_install_hook_types: [pre-commit, commit-msg]
 default_stages: [pre-commit]
-files: '^(gdb|gdbserver|gdbsupport)/'
+# The ^\.git/COMMIT_EDITMSG$ is there to make sure commit-msg hooks work.
+# See this issue ( https://github.com/pre-commit/pre-commit/issues/3720 ).
+files: '^(gdb|gdbserver|gdbsupport)/|^\.git/COMMIT_EDITMSG$'
 
 repos:
   # Python hooks.  Run these for (in glob notation):

base-commit: a4481c8ff808e7237b99815d84b0d4c06ded6124
-- 
2.51.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.