我期待svn提交消息中的以下格式。
描述:(某些变化的描述)
实体:(更改请求编号)
如果提交时的注释不符合上述格式,则应抛出错误消息。我们的想法是在提交消息中检查密钥字符串“Description”和“Entity”。我也在检查消息中是否存在评论。
我使用以下代码,但我无法检查字符串“Description”是否正常工作。 (对空注释的检查工作正常。)你能告诉我可能做错了吗?
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“描述”以及grep -w“描述”。仍然无法得到它。
答案 0 :(得分:0)
得到一个小的解决方法。 使用
LOGMSG=$($SVNLOOK log -t "$TXN" "$REPOS" | grep -w "Description" | wc -c)
if [ "$LOGMSG" -le 0 ]; then echo -e "Please provide a description when committing changes." 1>&2
exit 1
fi