I am trying to enforce a policy where each push gets rejected when even one of the commit messages does not satisfy a rule. I've distributed a hook to the devs in order for them to use it in their local repos but I also want to enforce this when they push to the origin.
I have two questions:
Should I use the update hook or the pre-receive hook? (I've tried to setup an update.secondary hook but it seems to me it doesn't get fired, while a pre-receive does).
How can I get the message for each commit contained in the push? More specifically, I want each commit message to have a specific "valid" (for my needs) prefix. So I would like to scan for every commit in this push the commit message and validate it before I accept the push.
I am using simple bash to code the hooks.
Thanks!
Instead of using chained update hook, I would recommend using VREFS, available with Gitolite V3. You can see all its arguments here.
Since a VREF is basically like a
git update
hook, you can, like in this script, get the log message for each commits withgit log --format=%s -1 $commit
:Example of a script enforcing a policy on git commit messages:
cwhsu mentions in the comments: