2013-03-13 87 views
0

我期待在svn commit消息中使用以下格式。檢查提交消息中的特定字符串 - SVN Precommit Hook

說明:(改變的一些描述)
實體:(改變請求數目)

如果在提交不遵循上述格式的錯誤消息應該被拋出的評論。這個想法是在提交消息中檢查關鍵字串「描述」和「實體」。我還檢查消息中是否存在評論。

我正在使用下面的代碼,但我無法得到檢查字符串「說明」工作。 (儘管對於null評論的檢查工作正常。)你能告訴我可能做錯了什麼嗎?

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

有一個小的解決方法。 二手

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