【问题标题】:Checking for specific string in commit message - SVN Precommit Hook检查提交消息中的特定字符串 - SVN Precommit Hook
【发布时间】:2013-03-01 11:36:11
【问题描述】:

我期望 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"。还是收不到。

【问题讨论】:

    标签: svn shell unix pre-commit-hook pre-commit


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-20
      • 2017-01-18
      • 1970-01-01
      • 2012-05-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多