Path: blob/main/sys/contrib/openzfs/scripts/commitcheck.sh
48266 views
#!/bin/sh12REF="HEAD"34# test commit body for length5# lines containing urls are exempt for the length limit.6test_commit_bodylength()7{8length="72"9body=$(git log --no-show-signature -n 1 --pretty=%b "$REF" | grep -Ev "http(s)*://" | grep -E -m 1 ".{$((length + 1))}")10if [ -n "$body" ]; then11echo "error: commit message body contains line over ${length} characters"12return 113fi1415return 016}1718# check for a tagged line19check_tagged_line()20{21regex='^[[:space:]]*'"$1"':[[:space:]][[:print:]]+[[:space:]]<[[:graph:]]+>$'22foundline=$(git log --no-show-signature -n 1 "$REF" | grep -E -m 1 "$regex")23if [ -z "$foundline" ]; then24echo "error: missing \"$1\""25return 126fi2728return 029}3031# check commit message for a normal commit32new_change_commit()33{34error=03536# subject is not longer than 72 characters37long_subject=$(git log --no-show-signature -n 1 --pretty=%s "$REF" | grep -E -m 1 '.{73}')38if [ -n "$long_subject" ]; then39echo "error: commit subject over 72 characters"40error=141fi4243# need a signed off by44if ! check_tagged_line "Signed-off-by" ; then45error=146fi4748# ensure that no lines in the body of the commit are over 72 characters49if ! test_commit_bodylength ; then50error=151fi5253return "$error"54}5556is_coverity_fix()57{58# subject starts with Fix coverity defects means it's a coverity fix59subject=$(git log --no-show-signature -n 1 --pretty=%s "$REF" | grep -E -m 1 '^Fix coverity defects')60if [ -n "$subject" ]; then61return 062fi6364return 165}6667coverity_fix_commit()68{69error=07071# subject starts with Fix coverity defects: CID dddd, dddd...72subject=$(git log --no-show-signature -n 1 --pretty=%s "$REF" |73grep -E -m 1 'Fix coverity defects: CID [[:digit:]]+(, [[:digit:]]+)*')74if [ -z "$subject" ]; then75echo "error: Coverity defect fixes must have a subject line that starts with \"Fix coverity defects: CID dddd\""76error=177fi7879# need a signed off by80if ! check_tagged_line "Signed-off-by" ; then81error=182fi8384# test each summary line for the proper format85OLDIFS=$IFS86IFS='87'88for line in $(git log --no-show-signature -n 1 --pretty=%b "$REF" | grep -E '^CID'); do89if ! echo "$line" | grep -qE '^CID [[:digit:]]+: ([[:graph:]]+|[[:space:]])+ \(([[:upper:]]|\_)+\)'; then90echo "error: commit message has an improperly formatted CID defect line"91error=192fi93done94IFS=$OLDIFS9596# ensure that no lines in the body of the commit are over 72 characters97if ! test_commit_bodylength; then98error=199fi100101return "$error"102}103104if [ -n "$1" ]; then105REF="$1"106fi107108# if coverity fix, test against that109if is_coverity_fix; then110if ! coverity_fix_commit; then111exit 1112else113exit 0114fi115fi116117# have a normal commit118if ! new_change_commit ; then119exit 1120fi121122exit 0123124125