Skip to content

Instantly share code, notes, and snippets.

@typeless
Created December 22, 2022 02:57
Show Gist options
  • Save typeless/e13d7f05162835d6453584b3364337b5 to your computer and use it in GitHub Desktop.
Save typeless/e13d7f05162835d6453584b3364337b5 to your computer and use it in GitHub Desktop.
Git hooks pre-receive checks trailers
#!/bin/bash
echo "Checking commit messages..."
# Iterate over the pushed commits
while read old_rev new_rev refname; do
# Get the list of commits being pushed
commits=$(git rev-list --reverse $old_rev..$new_rev)
# Iterate over the commits
for commit in $commits; do
# Check for the "Reviewed-by" and "Signed-off-by" trailers in the commit message
if ! git log -1 --format=%B $commit | grep -q 'Reviewed-by:' && ! git log -1 --format=%B $commit | grep -q 'Signed-off-by:'; then
# If either trailer is not present, print an error message and exit with a non-zero exit code
echo "Error: Commit $commit is missing the 'Reviewed-by:' and 'Signed-off-by:' trailers."
exit 1
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment