当没有输入提交注释时,是否有人知道如何阻止提交Subversion代码存储库?
答案 0 :(得分:58)
您可以使用钩子(将其放入<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/
答案 1 :(得分:19)
这是一个预提交钩子,其中包含@ 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
答案 2 :(得分:18)
实际上,当您创建Subversion存储库时,其hooks
子目录已包含钩子样本。查看名为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机器上是可执行的。
答案 3 :(得分:6)
创建预提交挂钩。这里有some instructions关于如何自己做,或者here是一个示例钩子脚本,它将拒绝任何提交短消息超过10个字符的内容。
答案 4 :(得分:6)
如果您只使用TortoiseSVN,则可以将TortoiseSVN的属性添加到根目录:
财产名称:tsvn:logminsize
价值:1
这将禁用TortoiseSVN提交窗口中的OK按钮,然后消息为空。
请注意,此属性是TortoiseSVN,具体可能与其他SVN客户端不兼容。
答案 5 :(得分:5)
超过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