9 if ! curl --output /dev/null --max-time 60 \
10 --silent --head --fail "$url" ; then
11 echo "\"$url\" is unreachable"
18 # test commit body for length
19 # lines containing urls are exempt for the length limit.
20 function test_commit_bodylength()
23 body=$(git log -n 1 --pretty=%b "$REF" | grep -Ev "http(s)*://" | grep -E -m 1 ".{$((length + 1))}")
24 if [ -n "$body" ]; then
25 echo "error: commit message body contains line over ${length} characters"
32 # check for a tagged line
33 function check_tagged_line()
35 regex='^\s*'"$1"':\s[[:print:]]+\s<[[:graph:]]+>$'
36 foundline=$(git log -n 1 "$REF" | grep -E -m 1 "$regex")
37 if [ -z "$foundline" ]; then
38 echo "error: missing \"$1\""
45 # check for a tagged line and check that the link is valid
46 function check_tagged_line_with_url()
48 regex='^\s*'"$1"':\s\K([[:graph:]]+)$'
49 foundline=$(git log -n 1 "$REF" | grep -Po "$regex")
50 if [ -z "$foundline" ]; then
51 echo "error: missing \"$1\""
57 for url in $(echo -e "$foundline"); do
58 if ! test_url "$url"; then
67 # check commit message for a normal commit
68 function new_change_commit()
72 # subject is not longer than 72 characters
73 long_subject=$(git log -n 1 --pretty=%s "$REF" | grep -E -m 1 '.{73}')
74 if [ -n "$long_subject" ]; then
75 echo "error: commit subject over 72 characters"
79 # need a signed off by
80 if ! check_tagged_line "Signed-off-by" ; then
84 # ensure that no lines in the body of the commit are over 72 characters
85 if ! test_commit_bodylength ; then
92 function is_openzfs_port()
94 # subject starts with OpenZFS means it's an openzfs port
95 subject=$(git log -n 1 --pretty=%s "$REF" | grep -E -m 1 '^OpenZFS')
96 if [ -n "$subject" ]; then
103 function openzfs_port_commit()
107 # subject starts with OpenZFS dddd
108 subject=$(git log -n 1 --pretty=%s "$REF" | grep -E -m 1 '^OpenZFS [[:digit:]]+(, [[:digit:]]+)* - ')
109 if [ -z "$subject" ]; then
110 echo "error: OpenZFS patch ports must have a subject line that starts with \"OpenZFS dddd - \""
114 # need an authored by line
115 if ! check_tagged_line "Authored by" ; then
119 # need a reviewed by line
120 if ! check_tagged_line "Reviewed by" ; then
124 # need ported by line
125 if ! check_tagged_line "Ported-by" ; then
129 # need a url to openzfs commit and it should be valid
130 if ! check_tagged_line_with_url "OpenZFS-commit" ; then
134 # need a url to illumos issue and it should be valid
135 if ! check_tagged_line_with_url "OpenZFS-issue" ; then
142 function is_coverity_fix()
144 # subject starts with Fix coverity defects means it's a coverity fix
145 subject=$(git log -n 1 --pretty=%s "$REF" | grep -E -m 1 '^Fix coverity defects')
146 if [ -n "$subject" ]; then
153 function coverity_fix_commit()
157 # subject starts with Fix coverity defects: CID dddd, dddd...
158 subject=$(git log -n 1 --pretty=%s "$REF" |
159 grep -E -m 1 'Fix coverity defects: CID [[:digit:]]+(, [[:digit:]]+)*')
160 if [ -z "$subject" ]; then
161 echo "error: Coverity defect fixes must have a subject line that starts with \"Fix coverity defects: CID dddd\""
165 # need a signed off by
166 if ! check_tagged_line "Signed-off-by" ; then
170 # test each summary line for the proper format
173 for line in $(git log -n 1 --pretty=%b "$REF" | grep -E '^CID'); do
174 echo "$line" | grep -E '^CID [[:digit:]]+: ([[:graph:]]+|[[:space:]])+ \(([[:upper:]]|\_)+\)' > /dev/null
175 # shellcheck disable=SC2181
176 if [[ $? -ne 0 ]]; then
177 echo "error: commit message has an improperly formatted CID defect line"
183 # ensure that no lines in the body of the commit are over 72 characters
184 if ! test_commit_bodylength; then
195 # if openzfs port, test against that
196 if is_openzfs_port; then
197 if ! openzfs_port_commit ; then
204 # if coverity fix, test against that
205 if is_coverity_fix; then
206 if ! coverity_fix_commit; then
213 # have a normal commit
214 if ! new_change_commit ; then