Path: blob/main/sys/contrib/openzfs/scripts/commitcheck.sh
102029 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" |10grep -Evi -e "http(s)*://" -e "signed-off-by:" -e "reviewed-by:" |11grep -E -m 1 ".{$((length + 1))}")12if [ -n "$body" ]; then13echo "error: commit message body contains line over ${length} characters"14return 115fi1617return 018}1920# check for a tagged line21check_tagged_line()22{23regex='^[[:space:]]*'"$1"':[[:space:]][[:print:]]+[[:space:]]<[[:graph:]]+>$'24foundline=$(git log --no-show-signature -n 1 "$REF" | grep -E -m 1 "$regex")25if [ -z "$foundline" ]; then26echo "error: missing \"$1\""27return 128fi2930return 031}3233# check commit message for a normal commit34new_change_commit()35{36error=03738# subject is not longer than 72 characters39long_subject=$(git log --no-show-signature -n 1 --pretty=%s "$REF" | grep -E -m 1 '.{73}')40if [ -n "$long_subject" ]; then41echo "error: commit subject over 72 characters"42error=143fi4445# need a signed off by46if ! check_tagged_line "Signed-off-by" ; then47error=148fi4950# ensure that no lines in the body of the commit are over 72 characters51if ! test_commit_bodylength ; then52error=153fi5455return "$error"56}5758is_coverity_fix()59{60# subject starts with Fix coverity defects means it's a coverity fix61subject=$(git log --no-show-signature -n 1 --pretty=%s "$REF" | grep -E -m 1 '^Fix coverity defects')62if [ -n "$subject" ]; then63return 064fi6566return 167}6869coverity_fix_commit()70{71error=07273# subject starts with Fix coverity defects: CID dddd, dddd...74subject=$(git log --no-show-signature -n 1 --pretty=%s "$REF" |75grep -E -m 1 'Fix coverity defects: CID [[:digit:]]+(, [[:digit:]]+)*')76if [ -z "$subject" ]; then77echo "error: Coverity defect fixes must have a subject line that starts with \"Fix coverity defects: CID dddd\""78error=179fi8081# need a signed off by82if ! check_tagged_line "Signed-off-by" ; then83error=184fi8586# test each summary line for the proper format87OLDIFS=$IFS88IFS='89'90for line in $(git log --no-show-signature -n 1 --pretty=%b "$REF" | grep -E '^CID'); do91if ! echo "$line" | grep -qE '^CID [[:digit:]]+: ([[:graph:]]+|[[:space:]])+ \(([[:upper:]]|\_)+\)'; then92echo "error: commit message has an improperly formatted CID defect line"93error=194fi95done96IFS=$OLDIFS9798# ensure that no lines in the body of the commit are over 72 characters99if ! test_commit_bodylength; then100error=1101fi102103return "$error"104}105106if [ -n "$1" ]; then107REF="$1"108fi109110# if coverity fix, test against that111if is_coverity_fix; then112if ! coverity_fix_commit; then113exit 1114else115exit 0116fi117fi118119# have a normal commit120if ! new_change_commit ; then121exit 1122fi123124exit 0125126127