-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpre-receive.2-commit_message
executable file
·61 lines (51 loc) · 2.06 KB
/
pre-receive.2-commit_message
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
#
# Guarantees that
# - commit messages are properly formatted (no full stop in subject, empty line between subject and body)
# - all commits to any branch contains a signed-off-by line
# - commits to precious branches additionally are acked-by someone
really_precious_branches=( stable )
zero="0000000000000000000000000000000000000000"
while read oldrev newrev refname; do
if [ "$newrev" = "$zero" ]; then
# deletes
continue
fi
if [ "$oldrev" != "$zero" ]; then
# not a create
pbranch=$(git rev-parse --symbolic --abbrev-ref $refname) || exit 13
for lbranch in "${really_precious_branches[@]}"; do
if [ "$lbranch" = "$pbranch" ]; then
commit=$(git rev-list -n 1 --all-match --invert-grep -E \
--grep '^Acked-by: .+ <.+@.+\..+>' "$oldrev..$newrev")
if [ -n "$commit" ]; then
echo "No Acked-by found in commit $commit for $refname (from $oldrev..$newrev), not pushing."
echo "git rev-list -n 1 --all-match --invert-grep -E --grep '^Acked-by: .+ <.+@.+\..+>' $oldrev..$newrev"
echo "Commit message was:"
git cat-file commit ${commit} | sed '1,/^$/d' | cat -n
exit 1
fi
fi
commit=$(git rev-list -n 1 --all-match --invert-grep -E \
--grep '^Signed-off-by: .+ <.+@.+\..+>' "$oldrev..$newrev")
if [ -n "$commit" ]; then
echo "No Signed-off-by found in commit $commit for $refname (from $oldrev..$newrev), not pushing."
echo "git rev-list -n 1 --all-match --invert-grep -E --grep '^Signed-off-by: .+ <.+@.+\..+>$' $oldrev..$newrev"
echo "Commit message was:"
git cat-file commit ${commit} | sed '1,/^$/d' | cat -n
exit 1
fi
done
fi
message=$(git cat-file commit ${newrev} | sed '1,/^$/d')
if [ ""$(echo "$message" | sed -nre '1!d;/.*[^[:alnum:]]$/p') != "" ]; then
echo "Non-alphanumeric character at the end of the first line of the commit message:"
echo "$message" | head -n1 | cat -n
exit 1
fi
if [ ""$(echo "$message" | sed -nre '2!d;s/^$/empty/p') != "empty" ]; then
echo "Second line of commit message is not empty:"
echo "$message" | head -n2 | cat -n
exit 1
fi
done