aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/check-patches
blob: 20291eb6f10d33c20a8cf99985a34dacddb8dd18 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/sh

set -e

revision_range="${1?revision range}"

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

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

	author=$(git log --format='%an <%ae>' -1 "$rev")
	if ! git log --format="%(trailers:key=Signed-off-by,only,valueonly)" -1 "$rev" |
			grep -qFx "$author"; then
		echo "error [PATCH $n/$total] '$title' 'Signed-off-by: $author' trailer is missing" >&2
		fail=true
	fi

	body=$(git log --format='%b' -1 "$rev")
	body=${body%$(git log --format='%(trailers)' -1 "$rev")}
	if [ "$(echo "$body" | wc -w)" -lt 3 ]; then
		echo "error [PATCH $n/$total] '$title' body has less than three words, please elaborate" >&2
		fail=true
	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