如何在没有注释的情况下阻止Subversion提交?

65 svn hook commit

当没有输入提交注释时,有没有人知道如何阻止提交到Subversion代码存储库?

mik*_*iku 59

你可以使用一个钩子(把它放入<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
Run Code Online (Sandbox Code Playgroud)

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

  • +1,但当然这不能强迫用户使用有意义的评论.svn commit -m"foo"foo.h仍然有用. (5认同)

pal*_*int 20

这是一个预提交钩子,其中包含@ 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
Run Code Online (Sandbox Code Playgroud)


Eli*_*kan 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
Run Code Online (Sandbox Code Playgroud)

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

  • 不应轻易使用@NamGiVU 777,如果所有者设置正确,您只需在文件上使用700或750即可使用. (2认同)
  • @NamGiVU你应该花一两天时间阅读关于linux的一般文档,因为你似乎缺乏一些基本技能(没有冒犯),看看这里有关于文件onwership和权限的快速课程:http://code.google. COM /教育/ tools101/LINUX/ownership_permissions.html (2认同)

Amb*_*ber 6

创建预提交挂钩.以下是有关如何自行完成的一些说明,或者是一个示例钩子脚本,它将拒绝任何短于10个字符的提交消息.

  • 这个答案有点"仅链接".难道你不能把钩子例子的内容放到答案中吗? (2认同)

rah*_*thi 6

Linux脚本超过15个字符 -

#!/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
Run Code Online (Sandbox Code Playgroud)

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


小智 6

如果您只使用TortoiseSVN,那么您可以将TortoiseSVN的属性添加到根目录:属性名称:tsvn:logminsize 值:1 这将禁用TortoiseSVN提交窗口中的OK按钮,然后消息为空.请注意,此属性是TortoiseSVN特定,它可能无法与其他SVN客户端一起使用.