我想要强制用户在git提交中添加JIRA票据。
我使用了一个pre-receive hook,但它只能在推送后才起作用。我希望它在提交后也能起作用,这样如果消息格式不正确,提交将失败,并且用户将有编辑提交的选项。
这是我的代码示例:
#!/usr/bin/env bash
# set this to your active development branch
#develop_branch="master"
#current_branch="$(git rev-parse --abbrev-ref HEAD)"
# only check commit messages on main development branch
#[ "$current_branch" != "$develop_branch" ] && exit 0
# regex to validate in commit msg
commit_regex='(#-[0-9]+|merge)'
error_msg="Aborting commit. Your commit message is missing either a JIRA Issue ('#-1111') '"
rm -rf fl.txt
echo $1 >> fl.txt
fil="fl.txt"
if ! grep -iE $commit_regex $fil; then
echo "$error_msg" >&2
exit 1
fi
rm -rf fl.txt