]> code.delx.au - gnu-emacs/blob - build-aux/git-hooks/commit-msg
Add git commit hooks that do some simple checks on commits.
[gnu-emacs] / build-aux / git-hooks / commit-msg
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.
25 cent_sign_utf8_octal='\302\242'
26 at_sign=`
27 printf "${cent_sign_utf8_octal}@" |
28 awk '{print substr($0, 2)}' 2>/dev/null
29 `
30 if 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
38 fi
39
40 # Check the log entry.
41 exec 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"