我似乎无处可去。在网上搜索脚本等等。任何人都有一个脚本,您可以在Windows环境中编辑现成的pre-commit.tmpl,该环境需要输入x字符才能在Tortoise Subversion中提交注释全局,以便团队中的所有成员都需要,而这个要求是从SVN服务器推送到客户端的?
我不知道脚本语言,如果没有花时间在接下来的3个小时内找出脚本,这应该是非常简单的事情。
答案 0 :(得分:55)
这是一个要求有评论的.bat文件。它会检查评论中是否存在至少一个字符。
@echo off
:: Stops commits that have empty log messages.
@echo off
setlocal
rem Subversion sends through the path to the repository and transaction id
set REPOS=%1
set TXN=%2
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 enter a comment. 1>&2
echo Write a log message describing the changes made and try again. 1>&2
echo Thanks 1>&2
exit 1
此文件位于存储库的/ hooks文件夹中,名为pre-commit.bat。如果您需要最少量的字符,则要修改的行是
svnlook log %REPOS% -t %TXN% | findstr . > nul
因此,如果你想要至少10个字符,你需要有10个字符而不是只有一个
svnlook log %REPOS% -t %TXN% | findstr .......... > nul
更多advanced options for the findstr命令可以让你进行更高级的检查(某些字符集等)
答案 1 :(得分:2)
我使用SubversionNotify,它可能比您需要的更多,但设置起来非常简单。
答案 2 :(得分:1)
试试这个:
rem Make sure that the log message contains some text.
set REPOS=%1
set TXN=%2
"C:\Program Files\Subversion\bin\SVNlook.exe" log -t %TXN% %REPOS% | FindStr [a-zA-Z0-9]
IF %ERRORLEVEL% EQU 0 GOTO OK
echo Your commit has been blocked because you didn't provide a 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
:OK
rem -------------------------------------------------------------
rem Check if comment is in list of reserved words to not be used..
rem -------------------------------------------------------------
"C:\Program Files\Subversion\bin\SVNlook.exe" log -t %TXN% %REPOS% >comment
setlocal enabledelayedexpansion
Set SEPARATOR=
set COMMENT=
for /f "delims=" %%a in (comment) do (
set currentline=%%a
set COMMENT=!COMMENT!%SEPARATOR%!currentline!
)
FIND "%COMMENT%" "C:\Program Files\Subversion\excludedwords.txt">Null
If %ERRORLEVEL% EQU 1 goto OK2
:Fail
echo Your commit has been blocked because the single word comment you provided is not allowed 1>&2
echo Line is -%COMMENT%- 1>&2
echo Please write a proper log message describing the purpose of your changes and 1>&2
echo then try committing again. -- Thank you 1>&2
exit 1
:OK2
rem -------------------------------------------------------------
rem Check number of words on the line if = 2 then reject comment
rem -------------------------------------------------------------
Set VAR1=%COMMENT%
Set count=0
For %%j in (%VAR1%) Do Set /A count+=1
IF %count% EQU 2 goto Fail2
goto OK3
:Fail2
echo Your commit has been blocked because not enough detail supplied 1>&2
echo Please write a longer log message describing the purpose of your changes and 1>&2
echo then try committing again. -- Thank you 1>&2
exit 1
:OK3
rem -------------------------------------------------------------
rem Check that the author of this commit has the rights to perform
rem -------------------------------------------------------------
rem the commit on the files and directories being modified.
rem commit-access-control.pl "$REPOS" "$TXN" commit-access-control.cfg || exit 1
rem All checks passed, so allow the commit.
exit 0
答案 3 :(得分:1)
我有pre-commit hook可以完全按照您的意愿行事。还有更多。
它还允许您执行以下操作:
svn cp
添加目录,但不提交任何更改。这非常适合允许您制作标记的/tags
目录,但不能修改标记。并且,它还允许您这样做:
svn:ignore
之类的内容非常有用,因此用户不会意外地提交他们不应提交的文件。svn:log
必须与某些正则表达式匹配。这个预提交脚本是用Perl编写的。默认情况下,Perl附带Unix,Mac和Linux服务器。不幸的是,它不包含在Windows计算机上。幸运的是,有几个开源,免费且易于安装的PC Perl软件包,例如ActivePerl和Strawberry Perl
答案 4 :(得分:1)
在Windows上,可以使用VisualSVN Server随附的VisualSVNServerHooks.exe check-logmessage
预提交钩子,该钩子位于%VISUALSVN_SERVER%bin
目录中。这个简单的工具将帮助您定义日志消息中允许的最小字符数。
有关说明,请参见文章KB140: Validating commit log messages in VisualSVN Server。