summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-04-27 01:22:01 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-04-30 00:43:09 +0300
commitfcfbec801bab520bcbb246f38f8efc448c901946 (patch)
tree4df9601361a096ae64bb651ed4279a5d406da9af /utils
parent7206035ee609d213156fd78cc78b14f9ce3f12dd (diff)
utils: hooks: pre-push: Catch commits without committer's SoB
Improve the pre-push git hook script to reject commits without the committer's Signed-off-by line. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Diffstat (limited to 'utils')
-rwxr-xr-xutils/hooks/pre-push31
1 files changed, 27 insertions, 4 deletions
diff --git a/utils/hooks/pre-push b/utils/hooks/pre-push
index 34906dde..0eb8f5ce 100755
--- a/utils/hooks/pre-push
+++ b/utils/hooks/pre-push
@@ -32,12 +32,35 @@ do
range="$remote_sha..$local_sha"
fi
+ #
# Find invalid commits.
- commit=$(git rev-list -n 1 --grep '^---' "$range")
- if [ -n "$commit" ]
+ #
+ errors=0
+ for commit in $(git rev-list "$range")
+ do
+ msg=$(git cat-file commit "$commit")
+
+ # 1. The commit message shall not contain a local changelog.
+ if echo "$msg" | grep -q '^--- *$'
+ then
+ echo >&2 "Found local changelog in commit $commit"
+ errors=$((errors+1))
+ fi
+
+ # 2. The commit message shall have a Signed-off-by line
+ # corresponding the committer.
+ committer=$(echo "$msg" | grep '^committer ' | head -1 | \
+ cut -d ' ' -f 2- | rev | cut -d ' ' -f 3- | rev)
+ if ! echo "$msg" | grep -F -q "Signed-off-by: ${committer}"
+ then
+ echo >&2 "Missing committer Signed-off-by in commit $commit"
+ errors=$((errors+1))
+ fi
+ done
+
+ if [ $errors != 0 ]
then
- echo >&2 "Found local changelog in $local_ref, not pushing"
- echo >&2 "Check commit $commit"
+ echo >&2 "Found $errors errors in $local_ref, not pushing"
exit 1
fi
done