You missed a hook. The one you want is commit-msg
:
This hook is invoked by git commit, and can be bypassed with –no-verify option. It takes a single parameter, the name of the file that holds the proposed commit log message. Exiting with non-zero status causes the git commit to abort.
So for example:
#!/bin/sh
ticket=$(git symbolic-ref HEAD | awk -F- '/^issue-/ {print $2}')
if [ -n "$ticket" ]; then
echo "ticket #$ticket" >> $1
fi
That’s a very naive parsing of your branch name, and it’s simply appended to the commit message on its own line. Modify it if that’s not good enough for you.
Of course, I’d actually recommend doing this in prepare-commit-msg
, and committing with git commit
(without -m
). It’s very, very rare that you can actually write sufficient information in a single-line commit message. Further, that will let you see the message before the commit is made, in case your hook doesn’t do quite what you want.