我们希望确保每个提交信息的主题中都包含一个Jira工单号码。例如,它应该像这样:“MA-12:修复了关于...的问题”。
我知道可以在客户端使用commit-msg钩子轻松完成此操作。但是,这不会自动为所有开发人员设置。有没有办法在服务器端完成这项工作?
我知道可以在客户端使用commit-msg钩子轻松完成此操作。但是,这不会自动为所有开发人员设置。有没有办法在服务器端完成这项工作?
padcom
编写):#!/bin/bash
refname="$1"
oldrev="$2"
newrev="$3"
result=0
# Make sure we handle the situation when the branch does not exist yet
if ! [ $oldrev = 0000000000000000000000000000000000000000 ] ; then
excludes=( ^$oldrev )
else
excludes=( $(git for-each-ref --format '^%(refname:short)' refs/heads/) )
fi
# Get the list of incomming commits
commits=`git rev-list $newrev "${excludes[@]}"`
# For every commit in the list
for commit in $commits
do
# check the log message for ticket number
message=`git log --format=%s -1 $commit`
ticket=`echo "$message" | grep -o "^[A-Z]\{2,3\}-[0-9]\+"`
if [ "$ticket" = "" ] ; then
echo "Commit $commit does not start with a ticket number"
result=1
fi
done
exit $result