aboutsummaryrefslogblamecommitdiffstats
path: root/contrib/check-patches
blob: 450eabae7e77239dd58f3a90bbbe49ffdb7e8438 (plain) (tree)
1
2
3
4
5
6
7
8
9





                                    
       

                                                     


                           
 
   







                                                      
                         
                    
                                                
                  
 
                                                      
                                                                                

          



                                                                
                                                        
                                                                                               
                                                 
                                                                 
          



                                                                
                                                                                  

          



                                               


                            



                                  
#!/bin/sh

set -e

revision_range="${1?revision range}"

valid=0
revisions=$(git rev-list --reverse "$revision_range")
total=$(echo $revisions | wc -w)
if [ "$total" -eq 0 ]; then
	exit 0
fi

n=0
title=
fail=false

err() {
	echo "error [PATCH $n/$total] '$title' $*" >&2
	fail=true
}

for rev in $revisions; do
	n=$((n + 1))
	title=$(git log --format='%s' -1 "$rev")
	fail=false

	if [ "$(echo "$title" | wc -m)" -gt 72 ]; then
		err "title is longer than 72 characters, please make it shorter"
	fi

	if ! echo "$title" | grep -q '^[a-z0-9,{}/_-]\+: '; then
		err "title lacks a topic prefix (e.g. 'imap:')"
	fi

	author=$(git log --format='%an <%ae>' -1 "$rev")
	if ! git log --format="%(trailers:key=Signed-off-by,only,valueonly,unfold)" -1 "$rev" |
			grep -qFx "$author"; then
		err "'Signed-off-by: $author' trailer is missing"
	fi

	body=$(git log --format='%b' -1 "$rev")
	body=${body%$(git log --format='%(trailers)' -1 "$rev")}
	if [ "$(echo "$body" | wc -w)" -lt 3 ]; then
		err "body has less than three words, please describe your changes"
	fi

	if [ "$fail" = true ]; then
		continue
	fi
	echo "ok    [PATCH $n/$total] '$title'"
	valid=$((valid + 1))
done

echo "$valid/$total valid patches"
if [ "$valid" -ne "$total" ]; then
	exit 1
fi