Я реализовал это в хуке commit-msg
. См. документацию .
commit-msg
This hook is invoked by git commit, and can be bypassed with the --no-verify option.
It takes a single parameter, the name of the file that holds the proposed commit log message.
Exiting with a non-zero status causes the git commit to abort.
Под my_git_project/.git/hooks
я добавил этот файл commit.msg
(должно быть это имя). Я добавил следующее содержимое bash в этот файл, который сделал проверку.
#!/usr/bin/env bash
INPUT_FILE=$1
START_LINE=`head -n1 $INPUT_FILE`
PATTERN="^(MYPROJ)-[[:digit:]]+: "
if ! [[ "$START_LINE" =~ $PATTERN ]]; then
echo "Bad commit message, see example: MYPROJ-123: commit message"
exit 1
fi