Skip to content

Commit

Permalink
scripts/check-signed-off: check that commits do not have an empty body
Browse files Browse the repository at this point in the history
Check that all new commits have a commit body besides the summary line
and git trailers.

Signed-off-by: Carlos López <carlos.lopez@suse.com>
  • Loading branch information
00xc committed Jan 11, 2024
1 parent eeab93f commit 971ed21
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions scripts/check-signed-off.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# Copyright (c) 2023 SUSE LLC
#
# Author: Carlos López <carlos.lopez@suse.com>
#
# Simple script to check that a commit has a Signed-off-by trailer and a
# nonempty commit body.

matches_any() {
needle=$1
Expand All @@ -18,6 +21,21 @@ matches_any() {
return 1
}

# Check that the body for the given commit is not empty
nonempty_body() {
body=$(git show --no-patch --format="%b" "$1" | sed '/^ *$/d')
trailers=$(git show --no-patch --format="%(trailers:only)" "$1")

# Remove trailers
for trailer in "${trailers[@]}"; do
body=$(echo "$body" | grep -F -v "$trailer")
done

# Return 1 if there is no body
[ -z "$body" ] && return 1
return 0
}

if [ $# -lt 1 ]; then
echo "Usage: $0 <start_commit> [<end_commit>]"
exit 1
Expand All @@ -35,6 +53,12 @@ for c in ${commits[@]}; do
parents=$(git cat-file -p "$c" | grep -c parent)
[ "$parents" -gt "1" ] && continue

nonempty_body "$c"
if [ "$?" != "0" ]; then
echo "Message body is empty for commit $c"
exit 1
fi

commit_email=$(git show --no-patch --pretty="format:%ae" "$c" || exit 1)
commit_name=$(git show --no-patch --pretty="format:%an" "$c" || exit 1)
sign_names=$(git show --no-patch "$c" | sed -nr 's/^[[:space:]]*Signed-off-by: (.*) <(.*)>/\1/p' || exit 1)
Expand Down

0 comments on commit 971ed21

Please sign in to comment.