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 v2] Do potentially destructive operations in prepare-commit-msg Date: Sun, 21 Apr 2019 23:17:30 +0300 Message-ID: <20190421201730.30905-1-Hi-Angel@yandex.ru> References: <20190421200313.26202-1-Hi-Angel@yandex.ru> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="143576"; 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:18:15 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 1hIIuk-000bDo-Ti for geb-bug-gnu-emacs@m.gmane.org; Sun, 21 Apr 2019 22:18:15 +0200 Original-Received: from localhost ([127.0.0.1]:56734 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hIIuj-0001j6-Uf for geb-bug-gnu-emacs@m.gmane.org; Sun, 21 Apr 2019 16:18:13 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:60976) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hIIud-0001iz-20 for bug-gnu-emacs@gnu.org; Sun, 21 Apr 2019 16:18:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hIIub-00064r-3l for bug-gnu-emacs@gnu.org; Sun, 21 Apr 2019 16:18:06 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35604) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hIIuY-00063p-Dy for bug-gnu-emacs@gnu.org; Sun, 21 Apr 2019 16:18:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hIIuY-00067X-86 for bug-gnu-emacs@gnu.org; Sun, 21 Apr 2019 16:18:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <20190421200313.26202-1-Hi-Angel@yandex.ru> Resent-From: Konstantin Kharlamov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 21 Apr 2019 20:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35368 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 35368-submit@debbugs.gnu.org id=B35368.155587786723495 (code B ref 35368); Sun, 21 Apr 2019 20:18:02 +0000 Original-Received: (at 35368) by debbugs.gnu.org; 21 Apr 2019 20:17:47 +0000 Original-Received: from localhost ([127.0.0.1]:49148 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hIIuI-00066t-Nd for submit@debbugs.gnu.org; Sun, 21 Apr 2019 16:17:47 -0400 Original-Received: from forward103o.mail.yandex.net ([37.140.190.177]:33184) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hIIuG-00066a-Cf for 35368@debbugs.gnu.org; Sun, 21 Apr 2019 16:17:45 -0400 Original-Received: from mxback22g.mail.yandex.net (mxback22g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:322]) by forward103o.mail.yandex.net (Yandex) with ESMTP id DE4DA5F80AE1 for <35368@debbugs.gnu.org>; Sun, 21 Apr 2019 23:17:36 +0300 (MSK) Original-Received: from smtp1o.mail.yandex.net (smtp1o.mail.yandex.net [2a02:6b8:0:1a2d::25]) by mxback22g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id oo6O4WUoVI-Ha0mMKKT; Sun, 21 Apr 2019 23:17:36 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1555877856; bh=oDcNr1ZcoI0YA3RP6uUzdslf+mh3usHxH6doRB0YYAY=; h=Subject:To:From:Date:Message-Id; b=Wy+i3RnJYSurz093f3PBmLV3S/GqJ6xsqSDBlqV/gh7/ZwjCefRMG5uU1qrtjwz51 PkPDk2SvWieJySgywemLM7xExVpYiFHbszrSbEWp7rQhRtTZ994GrzBA/91s7cEEJ4 bW/oPHXO4LOMu9mTFZK7jNjxIWDT58BjTkFDKC2Y= Authentication-Results: mxback22g.mail.yandex.net; dkim=pass header.i=@yandex.ru Original-Received: by smtp1o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id pLAE3cKHeq-Ha9mHe1e; Sun, 21 Apr 2019 23:17:36 +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-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:157966 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. --- v2: instead of "magic" $1 use $COMMIT_MSG_FILE 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= tailored_hooks= sample_hooks= -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="$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..f35f1dcbbc4 --- /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=$1 +COMMIT_SOURCE=$2 +SHA1=$3 + +# Prefer gawk if available, as it handles NUL bytes properly. +if type gawk >/dev/null 2>&1; then + awk=gawk +else + awk=awk +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='\302\242\n' +cent_sign=`printf "$cent_sign_utf8_format"` +print_at_sign='BEGIN {print substr("'$cent_sign'@", 2)}' +at_sign=`$awk "$print_at_sign" /dev/null` +if test "$at_sign" != @; then + at_sign=`LC_ALL=en_US.UTF-8 $awk "$print_at_sign" /dev/null` + if test "$at_sign" = @; then + LC_ALL=en_US.UTF-8 + else + LC_ALL=C + fi + export LC_ALL +fi + +exec $awk -v at_sign="$at_sign" -v cent_sign="$cent_sign" -v file="$COMMIT_MSG_FILE" ' + /^Signed-off-by: / { + print "'\''Signed-off-by:'\'' in commit message" + status = 1 + } + END { + if (status != 0) { + print "Commit aborted; please see the file 'CONTRIBUTE'" + } + exit status + } +' <"$COMMIT_MSG_FILE" -- 2.21.0