aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2014-11-22 15:46:17 -0800
committerPaul Eggert2014-11-22 16:41:10 -0800
commit00981cbdfff391d858d262083d24b685217a8353 (patch)
tree0d33bcdd109acfb640f24e146cc4b9f40a636612
parent238c052fdb9da3b1f96c09809461b70813c5bebc (diff)
downloademacs-00981cbdfff391d858d262083d24b685217a8353.tar.gz
emacs-00981cbdfff391d858d262083d24b685217a8353.zip
Add git commit hooks that do some simple checks on commits.
* autogen.sh: Install Git hooks, if using Git. * build-aux/git-hooks/commit-msg, build-aux/git-hooks/pre-commit: New files, which are Git hooks that check for portable file names, and do some simple checks for commit message format.
-rwxr-xr-xautogen.sh40
-rwxr-xr-xbuild-aux/git-hooks/commit-msg90
-rwxr-xr-xbuild-aux/git-hooks/pre-commit46
3 files changed, 176 insertions, 0 deletions
diff --git a/autogen.sh b/autogen.sh
index bc8a73db6bd..69812cdcfe0 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -208,6 +208,46 @@ autoreconf -i -I m4 || exit $?
208## cause 'make' to needlessly run 'autoheader'. 208## cause 'make' to needlessly run 'autoheader'.
209echo timestamp > src/stamp-h.in || exit 209echo timestamp > src/stamp-h.in || exit
210 210
211## Install Git hooks, if using Git.
212if test -d .git/hooks; then
213 tailored_hooks=
214 sample_hooks=
215
216 for hook in commit-msg pre-commit; do
217 cmp build-aux/git-hooks/$hook .git/hooks/$hook >/dev/null 2>&1 ||
218 tailored_hooks="$tailored_hooks $hook"
219 done
220 for hook in applypatch-msg pre-applypatch; do
221 cmp .git/hooks/$hook.sample .git/hooks/$hook >/dev/null 2>&1 ||
222 sample_hooks="$sample_hooks $hook"
223 done
224
225 if test -n "$tailored_hooks$sample_hooks"; then
226 echo "Installing git hooks..."
227
228 case `cp --help 2>/dev/null` in
229 *--backup*--verbose*)
230 cp_options='--backup=numbered --verbose';;
231 *)
232 cp_options='';;
233 esac
234
235 if test -n "$tailored_hooks"; then
236 for hook in $tailored_hooks; do
237 cp $cp_options build-aux/git-hooks/$hook .git/hooks || exit
238 chmod a-w .git/hooks/$hook || exit
239 done
240 fi
241
242 if test -n "$sample_hooks"; then
243 for hook in $sample_hooks; do
244 cp $cp_options .git/hooks/$hook.sample .git/hooks/$hook || exit
245 chmod a-w .git/hooks/$hook || exit
246 done
247 fi
248 fi
249fi
250
211echo "You can now run \`./configure'." 251echo "You can now run \`./configure'."
212 252
213exit 0 253exit 0
diff --git a/build-aux/git-hooks/commit-msg b/build-aux/git-hooks/commit-msg
new file mode 100755
index 00000000000..6a09eddf88b
--- /dev/null
+++ b/build-aux/git-hooks/commit-msg
@@ -0,0 +1,90 @@
1#!/bin/sh
2# Check the format of GNU Emacs change log entries.
3
4# Copyright 2014 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 <http://www.gnu.org/licenses/>.
20
21# Written by Paul Eggert.
22
23# Use a UTF-8 locale if available, so that the UTF-8 check works.
24# Use U+00A2 CENT SIGN to test whether the locale works.
25cent_sign_utf8_octal='\302\242'
26at_sign=`
27 printf "${cent_sign_utf8_octal}@" |
28 awk '{print substr($0, 2)}' 2>/dev/null
29`
30if test "$at_sign" != @; then
31 at_sign=`
32 printf "${cent_sign_utf8_octal}@" |
33 LC_ALL=en_US.utf8 awk '{print substr($0, 2)}' 2>/dev/null
34 `
35 if test "$at_sign" = @; then
36 LC_ALL=en_US.utf8; export LC_ALL
37 fi
38fi
39
40# Check the log entry.
41exec awk '
42 /^#/ { next }
43
44 !/^.*$/ {
45 print "Invalid character (not UTF-8)"
46 status = 1
47 }
48
49 nlines == 0 && !/[^[:space:]]/ { next }
50
51 { nlines++ }
52
53 nlines == 1 && /^[[:space:]]/ {
54 print "White space at start of first line"
55 status = 1
56 }
57
58 nlines == 2 && /[^[:space:]]/ {
59 print "Nonempty second line"
60 status = 1
61 }
62
63 /[[:cntrl:]]/ {
64 print "Text contains control character; please use spaces instead of tabs"
65 status = 1
66 }
67
68 72 < length && /[[:space:]]/ {
69 print "Line longer than 72 characters"
70 status = 1
71 }
72
73 140 < length {
74 print "Word longer than 140 characters"
75 status = 1
76 }
77
78 /^Signed-off-by: / {
79 print "'Signed-off-by:' present"
80 status = 1
81 }
82
83 END {
84 if (nlines == 0) {
85 print "Empty change log entry"
86 status = 1
87 }
88 exit status
89 }
90' <"$1"
diff --git a/build-aux/git-hooks/pre-commit b/build-aux/git-hooks/pre-commit
new file mode 100755
index 00000000000..c24f9bb48d3
--- /dev/null
+++ b/build-aux/git-hooks/pre-commit
@@ -0,0 +1,46 @@
1#!/bin/sh
2# Check file names in git commits for GNU Emacs.
3
4# Copyright 2014 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 <http://www.gnu.org/licenses/>.
20
21LC_ALL=C
22export LC_ALL
23
24exec >&2
25
26. git-sh-setup
27
28git_diff='git diff --cached --name-only --diff-filter=A'
29ok_chars='\0+[=-=]./0-9A-Z_a-z'
30nbadchars=`$git_diff -z HEAD | tr -d "$ok_chars" | wc -c`
31
32if test "$nbadchars" -ne 0; then
33 echo "File name does not consist of -+./_ or ASCII letters or digits."
34 exit 1
35fi
36
37new_names=`$git_diff HEAD` || exit
38case "
39$new_names" in
40 */-* | *'
41'-*)
42 echo "File name component begins with '-'."
43 exit 1;;
44esac
45
46exec git diff-index --check --cached HEAD --