如何在本地强制执行消息格式(我被迫包含refs #<ticket_no>
),这将阻止我提交。
如同git commit -m --ignore-fomrat ""
答案 0 :(得分:0)
你需要挂钩来完成这项任务。
挂钩可以在本地存储库中,但可以删除它们,因此您还需要在远程存储库中对其进行验证。
Sample post-commit hook
强> #!/bin/sh
#Pickup the commit details
while read oldrev newrev refname
do
branch=`echo $refname | cut -d'/' -f3`
old=`echo $oldrev | cut -c1-5`
new=`echo $newrev | cut -c1-5`
done
for rev in `git rev-list $old..$new`;do
message =`git cat-file commit $rev | sed '1,/^$/d'`
echo $message | grep -q ^'refs #'
if [ $? -ne 0 ] ;then
# Output colors
red='\033[0;31m';
green='\033[0;32m';
yellow='\033[0;33m';
default='\033[0;m';
# personal touch :-)
echo "${red}"
echo " "
echo " |ZZzzz "
echo " | "
echo " | "
echo " |ZZzzz /^\ |ZZzzz "
echo " | |~~~| | "
echo " | |- -| / \ "
echo " /^\ |[]+ | |^^^| "
echo " |^^^^^^^| | +[]| | | "
echo " | +[]|/\/\/\/\^/\/\/\/\/|^^^^^^^| "
echo " |+[]+ |~~~~~~~~~~~~~~~~~~| +[]| "
echo " | | [] /^\ [] |+[]+ | "
echo " | +[]+| [] || || [] | +[]+| "
echo " |[]+ | || || |[]+ | "
echo " |_______|------------------|_______| "
echo " "
echo " "
echo " ${green}Your message is unacceptable :-)${red} "
echo " Fix it if you wish to commit .!!! "
echo " "
echo "${default}"
exit 0
fi