emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

New Git hooks for checking file names in commit messages


From: Jim Porter
Subject: New Git hooks for checking file names in commit messages
Date: Thu, 20 Apr 2023 21:55:15 -0700

(For some background on this, see here: https://lists.gnu.org/archive/html/emacs-devel/2023-04/msg00274.html)

I've just merged some new Git hooks that should help to identify errors in the list of file names in commit messages (see commit 4416262f59f). These ensure that any file name listed in the commit message is actually in the diff, so that it's harder to make a typo when writing the commit message. The hooks recognize files on lines starting with "*" or "; *". This also means that if you want to use a "*" for a bulleted list of sentences, you should do something to make it not look like a file entry. For example, " *" is ok.

In addition to listing individual files, you can also list whole directories (e.g. if you added many files to a directory). However, you can't use wildcards in your file entries. (If people really want this, it's probably doable, but I think being explicit will help future maintainers if they ever need to grep the changelogs.)

You can install these hooks via the autogen.sh script, as usual. There's one part that might be surprising, at least initially though: while this is a hook to check commit messages, it actually runs in the post-commit and pre-push phases. This is because we want to examine the full diff of the commit in order to compare against the file entries in the message.[1] As a result, you'll just get an advisory message when you make the commit (it's too late to error out), and the pre-push hook will prevent you from pushing a badly-formatted commit message upstream.

I encourage everyone to test these hooks out and report back if you find any problems. I ran them locally on the last 5000 commits to master and manually verified that there are no false positives, but there could still be bugs. If you use a non-gawk awk, I especially encourage you to test them out. I did my best to only use POSIX awk features, but you never know...

[1] It's hard to do this during the commit-msg hook since there's no cross-platform way I know of to handle amending commits properly.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]