1 Commits

Author SHA1 Message Date
Bart van der Braak
ddc0881e24 Git hook to reject commit messages with HTML tags in them 2025-12-18 11:46:30 +01:00

View File

@@ -0,0 +1,48 @@
#!/bin/bash -eu
# Reject commits that contain HTML tags in their commit messages.
# Allow override with a special key phrase in the message.
set -o pipefail
nullsha="0000000000000000000000000000000000000000"
status=0
override_msg="override html check"
while read oldref newref refname; do
# Skip branch deletions
if [ "$newref" = "$nullsha" ]; then
continue
fi
# Handle new branches
if [ "$oldref" = "$nullsha" ]; then
oldref="HEAD"
fi
# Loop through each new commit
for commit in $(git rev-list ${oldref}..${newref}); do
# Get full commit message
msg=$(git log --format=%B -n 1 "$commit")
# Check for override
if echo "$msg" | grep -qi "$override_msg"; then
echo "Commit $commit allowed due to override message."
continue
fi
# Check for HTML tags
if echo "$msg" | grep -qE '</?[a-z][a-z0-9]*[^<>]*>'; then
echo "ERROR: Commit $commit contains HTML tags in the message."
echo "Message:"
echo "----------------------------------------"
echo "$msg"
echo "----------------------------------------"
echo "Please remove the HTML tags or use the override phrase:"
echo "\"$override_msg\""
status=1
fi
done
done
exit $status