all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jim Porter <jporterbugs@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: acm@muc.de, emacs-devel@gnu.org
Subject: Re: Mistakes in commit log messages
Date: Tue, 11 Apr 2023 17:20:26 -0700	[thread overview]
Message-ID: <693285d2-e50b-289d-4f3e-ddd817ddc75b@gmail.com> (raw)
In-Reply-To: <83v8i28b3j.fsf@gnu.org>

On 4/11/2023 12:36 PM, Eli Zaretskii wrote:
>> Date: Tue, 11 Apr 2023 12:27:40 -0700
>> Cc: acm@muc.de, emacs-devel@gnu.org
>> From: Jim Porter <jporterbugs@gmail.com>
>>
>> One issue with the current implementation (mentioned elsewhere in this
>> thread) is that it doesn't work for deleting a file from the repo.
>> Fixing this in the commit-msg hook is tricky. We can get the list of
>> changed files via "git diff --name-only" (and then we could compare our
>> commit message against that list), but there's a problem: I don't know
>> of a good way to detect when the user is amending a commit[1]. For a
>> normal commit, you'd get the changed files via something like "git diff
>> --staged --name-only", but for an amended commit, you'd want to add
>> "HEAD^" to that command.
> 
> If this will cry wolf on every removal or rename of a file, then this
> cure is worse than the disease, IMNSHO.  I'd prefer to waste a few
> hours of my time when preparing the tarball than risk annoying
> everyone with such false positives.

Yeah, I think doing this in a different hook would be less error-prone. 
Below is a demonstration of a post-commit hook that would warn the user 
about files listed in the commit message that aren't in the diff. The 
only potential for error I see is when creating or deleting entire 
directories, but that should be fixable by adding the parent directories 
of touched files into the 'CHANGES' variable.

Since this is a post-commit hook, it's only advisory, and can't error 
out. However, we could do something similar for a pre-push hook, except 
we'd iterate over each commit that's about to be pushed. A pre-push 
*could* error out, thus preventing users from pushing any 
badly-formatted commits upstream.

If we did something like this, I think both post-commit and pre-push 
hooks would be useful. The former gives committers immediate feedback on 
their commit message (if they read the output), while the latter is what 
ensures that the upstream commit messages are properly-formatted.

--------------------------------------------------

#!/bin/sh

git log -1 --format=%B | awk '
BEGIN {
   # Collect all the files touched in the last commit.
   while (("git log -1 --name-status --format=" | getline) > 0) {
     for (i = 2; i <= NF; i++) {
       CHANGES[$i] = 1
     }
   }
}

/^\* / {
   if (match($2, "[^:/][^:]*")) {
     FILE = substr($2, RSTART, RLENGTH)
     if (! (FILE in CHANGES)) {
       printf("File %s listed in commit message, but not in diff\n", FILE)
       status = 1
     }
   }
}

END {
   if (status != 0) {
     print "Bad commit; please see the file '\''CONTRIBUTE'\''"
   }
}
'



  reply	other threads:[~2023-04-12  0:20 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <835ya5m4p0.fsf@gnu.org>
     [not found] ` <ZDPkykCsW3i30UR9@ACM>
     [not found]   ` <83v8i4arzt.fsf@gnu.org>
     [not found]     ` <CANh=_JF0CEPDsWZSuyy9ymByma2LxcypP90O3-LQ+KhoJ8cqvg@mail.gmail.com>
     [not found]       ` <CANh=_JEO4-E79dPCLc3cRLi7=ftAzc+H1FC46eck1vJN3TD3Sg@mail.gmail.com>
2023-04-11  6:02         ` Mistakes in commit log messages Eli Zaretskii
2023-04-11 14:01           ` Alan Mackenzie
2023-04-11 14:57             ` Eli Zaretskii
2023-04-11 17:20               ` Alan Mackenzie
2023-04-11 18:00                 ` Eli Zaretskii
2023-04-11 18:31             ` Jim Porter
2023-04-11 18:45               ` Eli Zaretskii
2023-04-11 19:27                 ` Jim Porter
2023-04-11 19:36                   ` Eli Zaretskii
2023-04-12  0:20                     ` Jim Porter [this message]
2023-04-13  6:18                       ` Jim Porter
2023-04-13  6:49                         ` Eli Zaretskii
2023-04-13  7:47                           ` Robert Pluim
2023-04-15  3:41                           ` Jim Porter
2023-04-15  5:45                             ` Jim Porter
2023-04-15  7:15                               ` Eli Zaretskii
2023-04-15 10:44                                 ` Alan Mackenzie
2023-04-15 11:00                                   ` Eli Zaretskii
2023-04-21 22:16                                   ` Filipp Gunbin
2023-04-15 20:54                               ` Jim Porter
2023-04-15 21:23                                 ` Jim Porter
2023-04-16  5:43                                   ` Eli Zaretskii
2023-04-16 20:06                                     ` Jim Porter
2023-04-16 20:19                                       ` Michael Albinus
2023-04-17  2:22                                       ` Eli Zaretskii
2023-04-17  7:28                                         ` Michael Albinus
2023-04-21  4:59                                 ` Jim Porter
2023-04-15  7:08                             ` Eli Zaretskii
2023-04-12  9:41                     ` Alan Mackenzie
2023-04-12 10:14                       ` Eli Zaretskii
2023-04-12  9:32               ` Alan Mackenzie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=693285d2-e50b-289d-4f3e-ddd817ddc75b@gmail.com \
    --to=jporterbugs@gmail.com \
    --cc=acm@muc.de \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.