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 v4] Do potentially destructive operations in prepare-commit-msg Date: Thu, 16 May 2019 00:25:53 +0300 Message-ID: <20190515212553.5319-1-Hi-Angel@yandex.ru> References: <85k1erwr8r.fsf@gmail.com> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="41637"; 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 Wed May 15 23:27:16 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 1hR1Qf-000Ah2-FN for geb-bug-gnu-emacs@m.gmane.org; Wed, 15 May 2019 23:27:13 +0200 Original-Received: from localhost ([127.0.0.1]:42966 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hR1Qe-0004Uv-HE for geb-bug-gnu-emacs@m.gmane.org; Wed, 15 May 2019 17:27:12 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:37077) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hR1QW-0004UK-Rn for bug-gnu-emacs@gnu.org; Wed, 15 May 2019 17:27:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hR1QU-00073Z-Sk for bug-gnu-emacs@gnu.org; Wed, 15 May 2019 17:27:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:39971) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hR1QU-0006zi-Du for bug-gnu-emacs@gnu.org; Wed, 15 May 2019 17:27:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hR1QU-0002Fc-3I for bug-gnu-emacs@gnu.org; Wed, 15 May 2019 17:27: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: Wed, 15 May 2019 21:27: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.15579555808596 (code B ref 35368); Wed, 15 May 2019 21:27:02 +0000 Original-Received: (at 35368) by debbugs.gnu.org; 15 May 2019 21:26:20 +0000 Original-Received: from localhost ([127.0.0.1]:53514 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hR1Po-0002EZ-7o for submit@debbugs.gnu.org; Wed, 15 May 2019 17:26:20 -0400 Original-Received: from forward104j.mail.yandex.net ([5.45.198.247]:50715) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hR1Pl-0002EK-BQ for 35368@debbugs.gnu.org; Wed, 15 May 2019 17:26:19 -0400 Original-Received: from mxback7j.mail.yandex.net (mxback7j.mail.yandex.net [IPv6:2a02:6b8:0:1619::110]) by forward104j.mail.yandex.net (Yandex) with ESMTP id 1058F4A00C0 for <35368@debbugs.gnu.org>; Thu, 16 May 2019 00:26:10 +0300 (MSK) Original-Received: from smtp1o.mail.yandex.net (smtp1o.mail.yandex.net [2a02:6b8:0:1a2d::25]) by mxback7j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id jYEZqM6bwX-Q9ee8ie6; Thu, 16 May 2019 00:26:10 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1557955570; bh=XAC+kKLOlF21jztXFBqbYiWssUNZms9i/F4GHH6IJ3Y=; h=In-Reply-To:Subject:To:From:References:Date:Message-Id; b=QToD2iSj7MfYKTTr65ZZ/Y0kwCIsLcrAFxJXWSaJDDKSaSd9NiB8A40Kb6D4RQxYN YrXIeAcCtKTNOBGT3WzdtBkKxIN2DHYgBL7+ZLToIkJBYbwlfVDqQx5lVYxbu/1sdI 7+gka9UIQoduzu5UUOl+3RiwK7uRo7GuSrGYMtJg= Authentication-Results: mxback7j.mail.yandex.net; dkim=pass header.i=@yandex.ru Original-Received: by smtp1o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id hOB5BoQa73-Q9RaH0Jd; Thu, 16 May 2019 00:26:09 +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 In-Reply-To: <85k1erwr8r.fsf@gmail.com> 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:159358 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. --- v4: add a comment explaining how Signed-off could get there with -s option, and remove a stray space. autogen.sh | 2 +- build-aux/git-hooks/prepare-commit-msg | 45 ++++++++++++++++++++++++++ 2 files changed, 46 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..97b30263412 --- /dev/null +++ b/build-aux/git-hooks/prepare-commit-msg @@ -0,0 +1,45 @@ +#!/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 + +exec $awk ' + # catch the case when someone ran git-commit with -s option, + # which automatically adds Signed-off-by + /^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