检查在特定字符串提交信息 - SVN预提交挂钩(Checking for specific str

2019-08-17 13:31发布

我期待在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“说明”以及grep的-w“描述”了。 仍然不可能得到它。

Answer 1:

有一个轻微的解决方法。 用过的

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


文章来源: Checking for specific string in commit message - SVN Precommit Hook