]> git.proxmox.com Git - mirror_zfs.git/blame - scripts/commitcheck.sh
cstyle: Allow URLs in C++ comments
[mirror_zfs.git] / scripts / commitcheck.sh
CommitLineData
777b8ccc 1#!/bin/sh
cb524aa2
GDN
2
3REF="HEAD"
4
8dcaf243 5# test commit body for length
a584ef26 6# lines containing urls are exempt for the length limit.
777b8ccc 7test_commit_bodylength()
8dcaf243
GDN
8{
9 length="72"
10bcc4da 10 body=$(git log --no-show-signature -n 1 --pretty=%b "$REF" | grep -Ev "http(s)*://" | grep -E -m 1 ".{$((length + 1))}")
8dcaf243
GDN
11 if [ -n "$body" ]; then
12 echo "error: commit message body contains line over ${length} characters"
13 return 1
14 fi
15
16 return 0
17}
18
cb524aa2 19# check for a tagged line
777b8ccc 20check_tagged_line()
cb524aa2 21{
777b8ccc 22 regex='^[[:space:]]*'"$1"':[[:space:]][[:print:]]+[[:space:]]<[[:graph:]]+>$'
10bcc4da 23 foundline=$(git log --no-show-signature -n 1 "$REF" | grep -E -m 1 "$regex")
cb524aa2
GDN
24 if [ -z "$foundline" ]; then
25 echo "error: missing \"$1\""
26 return 1
27 fi
28
29 return 0
30}
31
cb524aa2 32# check commit message for a normal commit
777b8ccc 33new_change_commit()
cb524aa2
GDN
34{
35 error=0
36
4efb48ee 37 # subject is not longer than 72 characters
10bcc4da 38 long_subject=$(git log --no-show-signature -n 1 --pretty=%s "$REF" | grep -E -m 1 '.{73}')
cb524aa2 39 if [ -n "$long_subject" ]; then
4efb48ee 40 echo "error: commit subject over 72 characters"
cb524aa2
GDN
41 error=1
42 fi
43
44 # need a signed off by
45 if ! check_tagged_line "Signed-off-by" ; then
46 error=1
47 fi
48
49 # ensure that no lines in the body of the commit are over 72 characters
8dcaf243 50 if ! test_commit_bodylength ; then
cb524aa2
GDN
51 error=1
52 fi
53
83613696 54 return "$error"
cb524aa2
GDN
55}
56
777b8ccc 57is_coverity_fix()
8dcaf243
GDN
58{
59 # subject starts with Fix coverity defects means it's a coverity fix
10bcc4da 60 subject=$(git log --no-show-signature -n 1 --pretty=%s "$REF" | grep -E -m 1 '^Fix coverity defects')
8dcaf243
GDN
61 if [ -n "$subject" ]; then
62 return 0
63 fi
64
65 return 1
66}
67
777b8ccc 68coverity_fix_commit()
8dcaf243
GDN
69{
70 error=0
71
72 # subject starts with Fix coverity defects: CID dddd, dddd...
10bcc4da 73 subject=$(git log --no-show-signature -n 1 --pretty=%s "$REF" |
3da3488e 74 grep -E -m 1 'Fix coverity defects: CID [[:digit:]]+(, [[:digit:]]+)*')
8dcaf243
GDN
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
78 fi
79
80 # need a signed off by
81 if ! check_tagged_line "Signed-off-by" ; then
82 error=1
83 fi
84
85 # test each summary line for the proper format
86 OLDIFS=$IFS
777b8ccc
RM
87 IFS='
88'
10bcc4da 89 for line in $(git log --no-show-signature -n 1 --pretty=%b "$REF" | grep -E '^CID'); do
2ca77988 90 if ! echo "$line" | grep -qE '^CID [[:digit:]]+: ([[:graph:]]+|[[:space:]])+ \(([[:upper:]]|\_)+\)'; then
8dcaf243
GDN
91 echo "error: commit message has an improperly formatted CID defect line"
92 error=1
93 fi
94 done
95 IFS=$OLDIFS
96
97 # ensure that no lines in the body of the commit are over 72 characters
98 if ! test_commit_bodylength; then
99 error=1
100 fi
101
83613696 102 return "$error"
8dcaf243
GDN
103}
104
cb524aa2
GDN
105if [ -n "$1" ]; then
106 REF="$1"
107fi
108
8dcaf243
GDN
109# if coverity fix, test against that
110if is_coverity_fix; then
111 if ! coverity_fix_commit; then
112 exit 1
113 else
114 exit 0
115 fi
116fi
117
cb524aa2
GDN
118# have a normal commit
119if ! new_change_commit ; then
120 exit 1
121fi
122
123exit 0