检查提交消息中的特定字符串-SVN预提交挂钩

问题描述:

我期望svn commit消息中使用以下格式.

I am expecting the following format in the svn commit message.

说明:(有关更改的一些说明)
实体:(更改请求号)

Description: (some description of the change)
Entity: (change request number)

如果提交时的注释不遵循上述格式,则将引发错误消息.这个想法是检查提交消息中的关键字字符串"Description"和"Entity".我还在检查邮件中是否有评论.

If the comment while committing doesn't follow the above format an error message should be thrown. The idea is to check for the key strings "Description" and "Entity" in the commit message. I am also checking the presence of a comment in the message.

我正在使用以下代码,但无法获得对字​​符串"Description"的检查. (不过,对null注释的检查工作正常.)能否请您告诉我我可能做错了什么?

I am using the following code but I am not able to get that check for the string "Description" working. (The check for null comment is working fine though.) Could you please tell what I might be doing wrong?

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".还是没办法.

I tried with simple grep "Description" as well as grep -w "Description" too. Still couldnt get it.

有一个较小的解决方法. 二手

Got a minor workaround. Used

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