我期待 svn 提交消息中的以下格式。
描述:(变更的一些描述)
实体:(变更请求编号)
如果提交时的注释不符合上述格式,则应抛出错误消息。这个想法是检查提交消息中的关键字符串“描述”和“实体”。我还在检查消息中是否存在评论。
我正在使用以下代码,但我无法检查字符串“描述”是否正常工作。(虽然检查空评论工作正常。)你能告诉我可能做错了什么吗?
REPOS=$1
TXN=$2
LOG="/home/svn/testSVN/logs/precommithook.log"
GREP=/bin/grep
ECHO=/bin/echo
SVN="/usr/bin/svn";
SVNLOOK="/usr/bin/svnlook";
#Logs the current Transaction ID
"${ECHO}" "Transcation Id ${TXN}" >> "$LOG"
$SVNLOOK log "$REPOS" -t "$TXN" | grep "[a-zA-Z0-9]" > /dev/null
GREP_STATUS=$?
if [ $GREP_STATUS -ne 0 ]
then
"${ECHO}" "No Log comments present" >> "${LOG}"
echo "Your commit has been blocked because you didn't give any log message" 1>&2
echo "Please write a log message describing the purpose of your changes and" 1>&2
echo "then try committing again. -- Thank you" 1>&2
exit 1
fi
$SVNLOOK log "$REPOS" -t "$TXN" | grep [a-zA-Z0-9] | grep -q "Description" > /dev/null
GREP_DESCRIPTION_STATUS=$?
if [ $GREP_DESCRIPTION_STATUS –ne 0 ]
then
"${ECHO}" "Description not found in the comment" >> "${LOG}"
echo "Your commit has been blocked because you didn't give the Description in your commit message" 1>&2
echo "Please write a log message describing the purpose of your changes and" 1>&2
echo "then try committing again. -- Thank you" 1>&2
exit 1
fi
exit 0
我也尝试使用简单的 grep "Description" 以及 grep -w "Description"。还是拿不到。