From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Konstantin Kharlamov Newsgroups: gmane.emacs.bugs Subject: bug#35368: [PATCH] Do potentially destructive operations in prepare-commit-msg Date: Sun, 21 Apr 2019 23:03:13 +0300 Message-ID: <20190421200313.26202-1-Hi-Angel@yandex.ru> Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="83354"; mail-complaints-to="usenet@blaine.gmane.org" To: 35368@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Apr 21 22:04:20 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hIIhH-000LW5-QM for geb-bug-gnu-emacs@m.gmane.org; Sun, 21 Apr 2019 22:04:20 +0200 Original-Received: from localhost ([127.0.0.1]:56593 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hIIhG-0008B8-Po for geb-bug-gnu-emacs@m.gmane.org; Sun, 21 Apr 2019 16:04:18 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:58438) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hIIh2-0008Ar-LR for bug-gnu-emacs@gnu.org; Sun, 21 Apr 2019 16:04:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hIIh1-0005ob-5Z for bug-gnu-emacs@gnu.org; Sun, 21 Apr 2019 16:04:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35572) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hIIh0-0005oL-Mv for bug-gnu-emacs@gnu.org; Sun, 21 Apr 2019 16:04:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hIIh0-0005lB-Hp for bug-gnu-emacs@gnu.org; Sun, 21 Apr 2019 16:04:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Konstantin Kharlamov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 21 Apr 2019 20:04:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 35368 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.155587702222113 (code B ref -1); Sun, 21 Apr 2019 20:04:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 21 Apr 2019 20:03:42 +0000 Original-Received: from localhost ([127.0.0.1]:49116 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hIIgf-0005ka-OV for submit@debbugs.gnu.org; Sun, 21 Apr 2019 16:03:42 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:43982) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hIIgc-0005kN-BV for submit@debbugs.gnu.org; Sun, 21 Apr 2019 16:03:40 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:39638) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hIIgS-0005e2-T4 for submit@debbugs.gnu.org; Sun, 21 Apr 2019 16:03:32 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:58362) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hIIgR-00088b-Es for bug-gnu-emacs@gnu.org; Sun, 21 Apr 2019 16:03:28 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hIIgP-0005cw-I2 for bug-gnu-emacs@gnu.org; Sun, 21 Apr 2019 16:03:27 -0400 Original-Received: from forward101p.mail.yandex.net ([77.88.28.101]:39252) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hIIgN-0005bN-5Q for bug-gnu-emacs@gnu.org; Sun, 21 Apr 2019 16:03:24 -0400 Original-Received: from mxback13g.mail.yandex.net (mxback13g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:92]) by forward101p.mail.yandex.net (Yandex) with ESMTP id E5B4B3280D5B for ; Sun, 21 Apr 2019 23:03:18 +0300 (MSK) Original-Received: from smtp1p.mail.yandex.net (smtp1p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:6]) by mxback13g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id D2uDqyi8Hk-3IsSdYfC; Sun, 21 Apr 2019 23:03:18 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1555876998; bh=ofRtt8xXavgJGsQHA7DvzYRJGeyMOBe0PdD+fCHtPzU=; h=Subject:To:From:Date:Message-Id; b=Z+kfxKrnwmhZuU0Wq3XP/u/5TrCWYXx0U+KAjcBITGi30cBC4mtG2Kcq+x7sksWUC 5jslr70qCPDLNBjLjEpImXyy3w46QvXlO2XR4UbKMiZbWc9DIuettMmwbTh/6K3Fuw 6hpPg8ZaPqL6VA7vg3/9fsxqEvT3udO7AR9kT++4= Authentication-Results: mxback13g.mail.yandex.net; dkim=pass header.i=@yandex.ru Original-Received: by smtp1p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 7j2ljHPj7s-3IhSv6Qf; Sun, 21 Apr 2019 23:03:18 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) X-Mailer: git-send-email 2.21.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:157964 Archived-At: * build-aux/git-hooks/prepare-commit-msg: if someone occasionally puts Signed-off line, it will likely get there through -s option of git. Exploit this fact to abort before a user got a chance to type commit message. --- autogen.sh | 2 +- build-aux/git-hooks/prepare-commit-msg | 59 ++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100755 build-aux/git-hooks/prepare-commit-msg diff --git a/autogen.sh b/autogen.sh index 40d0c37b11b..c85ecfecac6 100755 --- a/autogen.sh +++ b/autogen.sh @@ -332,7 +332,7 @@ hooks=3D tailored_hooks=3D sample_hooks=3D =20 -for hook in commit-msg pre-commit; do +for hook in commit-msg pre-commit prepare-commit-msg; do cmp -- build-aux/git-hooks/$hook "$hooks/$hook" >/dev/null 2>&1 || tailored_hooks=3D"$tailored_hooks $hook" done diff --git a/build-aux/git-hooks/prepare-commit-msg b/build-aux/git-hooks= /prepare-commit-msg new file mode 100755 index 00000000000..ed4eab6063c --- /dev/null +++ b/build-aux/git-hooks/prepare-commit-msg @@ -0,0 +1,59 @@ +#!/bin/sh +# Check the format of GNU Emacs change log entries. + +# Copyright 2019 Free Software Foundation, Inc. + +# This file is part of GNU Emacs. + +# GNU Emacs is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# GNU Emacs is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with GNU Emacs. If not, see . + +COMMIT_MSG_FILE=3D$1 +COMMIT_SOURCE=3D$2 +SHA1=3D$3 + +# Prefer gawk if available, as it handles NUL bytes properly. +if type gawk >/dev/null 2>&1; then + awk=3Dgawk +else + awk=3Dawk +fi + +# Use a UTF-8 locale if available, so that the UTF-8 check works. +# Use U+00A2 CENT SIGN to test whether the locale works. +cent_sign_utf8_format=3D'\302\242\n' +cent_sign=3D`printf "$cent_sign_utf8_format"` +print_at_sign=3D'BEGIN {print substr("'$cent_sign'@", 2)}' +at_sign=3D`$awk "$print_at_sign" /dev/null` +if test "$at_sign" !=3D @; then + at_sign=3D`LC_ALL=3Den_US.UTF-8 $awk "$print_at_sign" /de= v/null` + if test "$at_sign" =3D @; then + LC_ALL=3Den_US.UTF-8 + else + LC_ALL=3DC + fi + export LC_ALL +fi + +exec $awk -v at_sign=3D"$at_sign" -v cent_sign=3D"$cent_sign" -v file=3D= "$1" ' + /^Signed-off-by: / { + print "'\''Signed-off-by:'\'' in commit message" + status =3D 1 + } + END { + if (status !=3D 0) { + print "Commit aborted; please see the file 'CONTRIBUTE'" + } + exit status + } +' <"$1" --=20 2.21.0