]> git.ozlabs.org Git - next-scripts/blob - check_commits
check_commits: tidy up a bit
[next-scripts] / check_commits
1 #!/bin/bash
2
3 if [ "$#" -lt 1 ]; then
4         printf "Usage: %s <commit range>\n", "$0" 1>&2
5         exit 1
6 fi
7
8 commits=$(git rev-list --no-merges "$@")
9 if [ -z "$commits" ]; then
10         printf "No commits\n"
11         exit 0
12 fi
13
14 author_missing=
15 committer_missing=
16
17 print_commits()
18 {
19         local t="$1"
20
21         shift
22
23         s=
24         is='is'
25         its='its'
26         [ "$#" -gt 1 ] && {
27                 s='s'
28                 is='are'
29                 its='their'
30         }
31         printf "Commit%s\n\n" "$s"
32         git log --no-walk --pretty='format:  %h ("%s")' "$@"
33         printf "\n%s missing a Signed-off-by from %s %s%s.\n" "$is" "$its" "$t" "$s"
34         printf "\n"
35 }
36
37 for c in $commits; do
38         ae=$(git log -1 --format='<%ae>%n<%aE>%n %an %n %aN ' "$c" | sort -u)
39         ce=$(git log -1 --format='<%ce>%n<%cE>%n %cn %n %cN ' "$c" | sort -u)
40         msg=$(git log -1 --format='%b' "$c")
41         sob=$(echo "$msg" | sed -En 's/^\s*Signed-off-by:?\s*/ /ip')
42
43         am=false
44         cm=false
45         grep -i -F -q "$ae" <<<"$sob" ||
46                 am=true
47         grep -i -F -q "$ce" <<<"$sob" ||
48                 cm=true
49         "$am" && author_missing+=" $c"
50         "$cm" && committer_missing+=" $c"
51 done
52
53 if [ "$author_missing" ]; then
54         print_commits "author" $author_missing
55 fi
56 if [ "$committer_missing" ]; then
57         print_commits "committer" $committer_missing
58 fi
59
60 exec gitk "$@"