I am trying to write a pre-receive hook to check the pattern of the commit messages using bash/shell.
I want to reject the entire push if any commit has issues. How to retrieve the commit messages?
There is an entire example, with explanations, in the git docs, that covers this. Link to the example.
Roughly translating the ruby example, we have:
#!/bin/bash
set -eo pipefail
refname="$0"
oldrev="$1"
newrev="$2"
echo "Enforcing Policies..."
# Iterate over all the commits
for commit in $(git rev-list 538c33..d14fc7); do
git cat-file commit "${commit}" | sed '1,/^$/d' | your-validator
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With