Created
August 30, 2024 20:00
-
-
Save rlee287/365abaad7b8879e0b086d5a0f4fcba99 to your computer and use it in GitHub Desktop.
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/sh | |
# This commit-msg git hook enforces the author of a commit signing off on it when not on a branch that contains the word "throwaway". | |
SIGNOFF_LINE=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') | |
echo "Checking for line $SIGNOFF_LINE" | |
# Check if signoff line is present | |
if ! grep -qs "^$SIGNOFF_LINE" "$1"; then | |
# If line is not present, check if we're on a branch with "throwaway" in it | |
echo "Commit is missing a signoff line" | |
# exit code 0 if branch, exit code 128 if detached | |
BRANCH_NAME=$(git symbolic-ref --short HEAD 2>/dev/null) | |
if [ $? -eq 0 ]; then | |
echo "$BRANCH_NAME" | grep -qs -F 'throwaway' | |
if [ $? -ne 0 ]; then | |
echo "Not on a throwaway branch, failing" | |
exit 1 | |
else | |
echo "Exempt: on a throwaway branch" | |
fi | |
else | |
echo "Exempt: HEAD is detached" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment