我怎样才能防止Subversion提交没有评论?

有没有人知道如何防止提交到一个Subversion代码库没有input提交评论?

你可以使用一个钩子(把它放在<repository>/hooks并把它命名为pre-commit.bat (Windows)):

 @echo off :: :: Stops commits that have empty log messages. :: setlocal rem Subversion sends through the path to the repository and transaction id set REPOS=%1 set TXN=%2 rem check for an empty log message svnlook log %REPOS% -t %TXN% | findstr . > nul if %errorlevel% gtr 0 (goto err) else exit 0 :err echo. 1>&2 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 

src: http : //www.anujgakhar.com/2008/02/14/how-to-force-comments-on-svn-commit/

这是一个预先提交的钩子@ miku的详细的错误信息为Linux:

 #!/bin/sh REPOS="$1" TXN="$2" SVNLOOK=/usr/bin/svnlook $SVNLOOK log -t "$TXN" "$REPOS" | \ grep "[a-zA-Z0-9]" > /dev/null GREP_STATUS=$? if [ $GREP_STATUS -ne 0 ] then 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 exit 0 

实际上,当你创build一个Subversion版本库时,它的hooks子目录已经包含了hook样本。 查看一个名为pre-commit.tmpl的钩子参数的细节。 它还包含一个你正在寻找的钩子的例子:

 #!/bin/sh REPOS="$1" TXN="$2" # Make sure that the log message contains some text. SVNLOOK=/usr/local/bin/svnlook $SVNLOOK log -t "$TXN" "$REPOS" | \ grep "[a-zA-Z0-9]" > /dev/null || exit 1 

你可以用任何脚本或语言编写你的钩子,只要它在你的Subversion机器上是可执行的。

创build一个预先提交的钩子。 下面是关于如何自己做的一些说明 ,或者这里是一个钩子脚本示例,它会拒绝less于10个字符的提交消息。

超过15个字符的Linux脚本 –

 #!/bin/bash REPOS="$1" TXN="$2" # Make sure that the log message contains some text. SVNLOOK=/usr/bin/svnlook # Comments should have more than 5 characters LOGMSG=$($SVNLOOK log -t "$TXN" "$REPOS" | grep [a-zA-Z0-9] | wc -c) if [ "$LOGMSG" -lt 15 ]; then echo -e "Please provide a meaningful comment when committing changes." 1>&2 exit 1 fi 

来源 – http://java.dzone.com/articles/useful-subversion-pre-commit

如果只使用TortoiseSVN,则可以将TortoiseSVN的属性添加到根目录:属性名称: tsvn:logminsize value: 1这将在TortoiseSVN提交窗口中禁用“确定”button,然后“消息”为空。 请注意,这个属性是TortoiseSVN具体可能不适用于其他SVN客户端。