rpm: Keep debug symbols if configured with '--enable-debuginfo'
[zfs.git] / scripts / commitcheck.sh
blob1b1d097501dbf0e396e931c006f6dddbf90d7dce
1 #!/bin/sh
3 REF="HEAD"
5 # test commit body for length
6 # lines containing urls are exempt for the length limit.
7 test_commit_bodylength()
9 length="72"
10 body=$(git log --no-show-signature -n 1 --pretty=%b "$REF" | grep -Ev "http(s)*://" | grep -E -m 1 ".{$((length + 1))}")
11 if [ -n "$body" ]; then
12 echo "error: commit message body contains line over ${length} characters"
13 return 1
16 return 0
19 # check for a tagged line
20 check_tagged_line()
22 regex='^[[:space:]]*'"$1"':[[:space:]][[:print:]]+[[:space:]]<[[:graph:]]+>$'
23 foundline=$(git log --no-show-signature -n 1 "$REF" | grep -E -m 1 "$regex")
24 if [ -z "$foundline" ]; then
25 echo "error: missing \"$1\""
26 return 1
29 return 0
32 # check commit message for a normal commit
33 new_change_commit()
35 error=0
37 # subject is not longer than 72 characters
38 long_subject=$(git log --no-show-signature -n 1 --pretty=%s "$REF" | grep -E -m 1 '.{73}')
39 if [ -n "$long_subject" ]; then
40 echo "error: commit subject over 72 characters"
41 error=1
44 # need a signed off by
45 if ! check_tagged_line "Signed-off-by" ; then
46 error=1
49 # ensure that no lines in the body of the commit are over 72 characters
50 if ! test_commit_bodylength ; then
51 error=1
54 return "$error"
57 is_coverity_fix()
59 # subject starts with Fix coverity defects means it's a coverity fix
60 subject=$(git log --no-show-signature -n 1 --pretty=%s "$REF" | grep -E -m 1 '^Fix coverity defects')
61 if [ -n "$subject" ]; then
62 return 0
65 return 1
68 coverity_fix_commit()
70 error=0
72 # subject starts with Fix coverity defects: CID dddd, dddd...
73 subject=$(git log --no-show-signature -n 1 --pretty=%s "$REF" |
74 grep -E -m 1 'Fix coverity defects: CID [[:digit:]]+(, [[:digit:]]+)*')
75 if [ -z "$subject" ]; then
76 echo "error: Coverity defect fixes must have a subject line that starts with \"Fix coverity defects: CID dddd\""
77 error=1
80 # need a signed off by
81 if ! check_tagged_line "Signed-off-by" ; then
82 error=1
85 # test each summary line for the proper format
86 OLDIFS=$IFS
87 IFS='
89 for line in $(git log --no-show-signature -n 1 --pretty=%b "$REF" | grep -E '^CID'); do
90 if ! echo "$line" | grep -qE '^CID [[:digit:]]+: ([[:graph:]]+|[[:space:]])+ \(([[:upper:]]|\_)+\)'; then
91 echo "error: commit message has an improperly formatted CID defect line"
92 error=1
94 done
95 IFS=$OLDIFS
97 # ensure that no lines in the body of the commit are over 72 characters
98 if ! test_commit_bodylength; then
99 error=1
102 return "$error"
105 if [ -n "$1" ]; then
106 REF="$1"
109 # if coverity fix, test against that
110 if is_coverity_fix; then
111 if ! coverity_fix_commit; then
112 exit 1
113 else
114 exit 0
118 # have a normal commit
119 if ! new_change_commit ; then
120 exit 1
123 exit 0