问题描述
我正在寻找一种通过预接收挂钩验证提交消息的方法。
我能够验证它是否可以压缩并合并提交,但是它不适用于github rebase和merge。
你能帮我吗?
set -e
zero_commit='0000000000000000000000000000000000000000'
msg_regex='<pattern_here>'
release_branches=( topic master )
exit_code=0
containsElement () {
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && return 0; done
return 1
}
while read oldsha newsha refname; do
short_current_branch="$(echo ${refname} | sed 's/refs\/heads\///g')"
if containsElement "${short_current_branch}" "${release_branches[@]}"; then
echo "${short_current_branch} is in ${release_branches[@]}"
else
echo "${short_current_branch} is not in ${release_branches[@]}"
echo "Skipping execution"
continue
fi
case ${oldsha},${newsha} in
*,${NULL_SHA1}) # it's a delete
any_deleted=true;;
${NULL_SHA1},*) # it's a create
new_list="$new_list $newsha";;
*,*) # it's an update
new_list="$new_list $newsha";;
esac
done
if [[ -z "$new_list" ]]
then
exit ${exit_code}
fi
commit_msg=()
git rev-list ${new_list} --not --all |
while read sha1; do
message=$( git log --max-count=1 --format=%B ${sha1} | head -1)
if ! echo "${message}" | grep -o "<regex_pattern>" ; then
echo "ERROR:"
echo "ERROR: Your push was rejected because commit: ${commit}"
echo "ERROR: is missing radar link in first line of below commit message:"
echo "ERROR: ${message}"
echo "ERROR:"
echo "ERROR: Please fix commit message and push again."
echo "ERROR: https://docs.github.com/en/enterprise-
server@2.21/github/committing-
changes-to-your-project/changing-a-commit-message"
echo "ERROR"
exit_code=1
fi
done
exit ${exit_code}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)