From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jim Porter Newsgroups: gmane.emacs.devel Subject: Re: Mistakes in commit log messages Date: Tue, 11 Apr 2023 17:20:26 -0700 Message-ID: <693285d2-e50b-289d-4f3e-ddd817ddc75b@gmail.com> References: <835ya5m4p0.fsf@gnu.org> <83v8i4arzt.fsf@gnu.org> <838rezardu.fsf@gnu.org> <319d616d-9230-0a82-331f-0f57488e4c80@gmail.com> <834jpm9s1g.fsf@gnu.org> <83v8i28b3j.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17692"; mail-complaints-to="usenet@ciao.gmane.io" Cc: acm@muc.de, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Apr 12 02:21:24 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pmOEl-0004N3-N0 for ged-emacs-devel@m.gmane-mx.org; Wed, 12 Apr 2023 02:21:23 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmODy-0000Gt-IZ; Tue, 11 Apr 2023 20:20:34 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pmODw-0000GP-1f for emacs-devel@gnu.org; Tue, 11 Apr 2023 20:20:32 -0400 Original-Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmODu-0006li-5s; Tue, 11 Apr 2023 20:20:31 -0400 Original-Received: by mail-pj1-x102f.google.com with SMTP id d22-20020a17090a111600b0023d1b009f52so12802478pja.2; Tue, 11 Apr 2023 17:20:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681258828; x=1683850828; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=3KadsXy81P4tqEbC6Kvdc2QCdALFM2DXXWp3AcyAuow=; b=WAXIiO9+uZt6NM1Z8/V07bh7oDtABpBD9wL48zUuJ/0so8aDehhj3kh67XuzbAM0I+ XqJ1SyNnepIBv8kTeWCR6ib4fxLW+dTSnMZRx5TxVRHbwzcYf3dgJOF0JB/G688Bcvip YYJ2b7yuyIlLeXfuw076X4xUAHX02GQ2x3ndgpQPXkUYLGISf5lWSvwDaic/o7GI7ljA q/WI9tRPrR9oOKUllOvKBj4zH2vDYQ9VA2nkl+vmQXRdrT+F3k6Fgwp2Lje9S6SIx2/7 2b5+sQ+WjvHt00SWvhIx7XzwZ3bnmLruMeXFo4p7E+s4H66lrV5DJSEUXGNvpsck2E7J ATWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681258828; x=1683850828; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3KadsXy81P4tqEbC6Kvdc2QCdALFM2DXXWp3AcyAuow=; b=ZTflnbv6K4ou1/tcnafnJrlkRRk8pq4t2ilaTA46kfQ2Iz6uW1tIXw6ANpwFVzJn30 lmwWCjTnJNK9w7yF99H4ktFS780VnSYe79GVQDnmOq1onMzOJWHOghbOlwx9FVqr9/Qb 5hOca7gEQXG3BNpl/xGesnRmaw78+ufpw51NYNo8DItxcNf6m6yWT27qNJkh632jO3rH mZm6O57duN//UQdtDB68IoIntWzyin5ZXFmqK6JX8oTELemHLuwaL/Vt2sFfmwXIE5Gk JE/LEa0JhTNIgc1zO5o1OlReijCx0cWM7/fpqmBuCTVQ66iEjXNVpDbJv+qXG+Dn6t/Y R0oQ== X-Gm-Message-State: AAQBX9diTi/X8dhC64gCEO7PZbrhChOYa8dfkjLyzROqmidgfG0x0FIB I49RtlE+KHWXJRRbzOeGYOsRJhpOWS/MnA== X-Google-Smtp-Source: AKy350aJ3Pi30XBgMXbyn+jd8aScdgv3hOcV0/Oz74YApFvQMsGcG4boezbiFlLoFrZh+YBC8eds2Q== X-Received: by 2002:a17:902:d4ce:b0:1a0:6bd4:ea78 with SMTP id o14-20020a170902d4ce00b001a06bd4ea78mr15660336plg.31.1681258827781; Tue, 11 Apr 2023 17:20:27 -0700 (PDT) Original-Received: from [192.168.1.2] (cpe-76-168-148-233.socal.res.rr.com. [76.168.148.233]) by smtp.googlemail.com with ESMTPSA id q16-20020a170902dad000b0019ee045a2b3sm10241301plx.308.2023.04.11.17.20.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Apr 2023 17:20:27 -0700 (PDT) Content-Language: en-US In-Reply-To: <83v8i28b3j.fsf@gnu.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=jporterbugs@gmail.com; helo=mail-pj1-x102f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:305254 Archived-At: 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 >> >> 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'\''" } } '