Created
December 22, 2022 02:57
-
-
Save typeless/e13d7f05162835d6453584b3364337b5 to your computer and use it in GitHub Desktop.
Git hooks pre-receive checks trailers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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