aboutsummaryrefslogtreecommitdiffstats
path: root/build-aux/git-hooks/prepare-commit-msg
diff options
context:
space:
mode:
authorKonstantin Kharlamov2019-05-16 00:25:53 +0300
committerNoam Postavsky2019-05-16 20:25:32 -0400
commit2bdc419f51630eb433deb139da67e419000c7694 (patch)
treee8aa4bab2a61a0f06e402fa4263ab430032afd2a /build-aux/git-hooks/prepare-commit-msg
parentcf5457764c1288ee34e01d82deb596950fc9f885 (diff)
downloademacs-2bdc419f51630eb433deb139da67e419000c7694.tar.gz
emacs-2bdc419f51630eb433deb139da67e419000c7694.zip
Do potentially destructive operations in prepare-commit-msg
* 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. (Bug#35368)
Diffstat (limited to 'build-aux/git-hooks/prepare-commit-msg')
-rwxr-xr-xbuild-aux/git-hooks/prepare-commit-msg45
1 files changed, 45 insertions, 0 deletions
diff --git a/build-aux/git-hooks/prepare-commit-msg b/build-aux/git-hooks/prepare-commit-msg
new file mode 100755
index 00000000000..3562a802234
--- /dev/null
+++ b/build-aux/git-hooks/prepare-commit-msg
@@ -0,0 +1,45 @@
1#!/bin/sh
2# Check the format of GNU Emacs change log entries.
3
4# Copyright 2019 Free Software Foundation, Inc.
5
6# This file is part of GNU Emacs.
7
8# GNU Emacs is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12
13# GNU Emacs is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17
18# You should have received a copy of the GNU General Public License
19# along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
20
21COMMIT_MSG_FILE=$1
22COMMIT_SOURCE=$2
23SHA1=$3
24
25# Prefer gawk if available, as it handles NUL bytes properly.
26if type gawk >/dev/null 2>&1; then
27 awk=gawk
28else
29 awk=awk
30fi
31
32exec $awk '
33 # Catch the case when someone ran git-commit with -s option,
34 # which automatically adds Signed-off-by.
35 /^Signed-off-by: / {
36 print "'\''Signed-off-by:'\'' in commit message"
37 status = 1
38 }
39 END {
40 if (status != 0) {
41 print "Commit aborted; please see the file 'CONTRIBUTE'"
42 }
43 exit status
44 }
45' <"$COMMIT_MSG_FILE"