1#! /usr/bin/env bash 2 3echoerr() { 4 printf "ERROR: %s\n" "$*" >&2 5} 6 7findtag() { 8 local commit_body tag person 9 commit_body=$1 10 tag=$2 11 person=$3 12 13 # trim duplicate spaces from commit body and person 14 match="$tag: $(echo $person | tr -s ' ')" 15 16 if [ -z "$(echo "$commit_body" | tr -s ' ' | grep -i "$match")" ]; then 17 echoerr "Tag is missing from commit body" 18 echoerr "" 19 echoerr "Looking for '"$match"' in: " 20 echoerr "-----------------------------------------------------" 21 echoerr "$commit_body" 22 echoerr "-----------------------------------------------------" 23 echoerr "" 24 return 0 25 fi 26 27 return 1 28} 29 30git fetch https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer.git 31 32git log --pretty='%h' FETCH_HEAD..HEAD | while read h; do 33 subject=$(git show -s --pretty='%s' "$h") 34 if [[ $subject != drm_hwcomposer:* ]]; then 35 echoerr "Invalid subject prefix: $subject" 36 exit 1 37 fi 38 39 commit_body=$(git show -s --pretty=%b "$h") 40 41 author=$(git show -s --format='%an <%ae>' "$h") 42 if findtag "$commit_body" "Signed-off-by" "$author"; then 43 echoerr "Author SoB tag is missing from commit $h" 44 exit 1 45 fi 46 47 committer=$(git show -s --format='%cn <%ce>' "$h") 48 if findtag "$commit_body" "Signed-off-by" "$committer"; then 49 echoerr "Committer SoB tag is missing from commit $h" 50 exit 1 51 fi 52 53 git show "$h" -- | clang-format-diff-5.0 -p 1 -style=file > format-fixup.patch 54 if [ -s format-fixup.patch ]; then 55 cat format-fixup.patch >&2 56 exit 1 57 fi 58done 59