我似乎在这方面一无所获。要么搜索网上的脚本等等。有人有一个脚本可以在Windows环境中编辑out-of-box pre-commit.tmpl,要求在Tortoise Subversion全局提交时输入x个字符的注释,以便所有团队成员都需要,而此要求从SVN服务器向客户端推送?
我不知道脚本语言,这应该是非常简单的事情,而不需要我花3个小时去学习脚本。
我似乎在这方面一无所获。要么搜索网上的脚本等等。有人有一个脚本可以在Windows环境中编辑out-of-box pre-commit.tmpl,要求在Tortoise Subversion全局提交时输入x个字符的注释,以便所有团队成员都需要,而此要求从SVN服务器向客户端推送?
我不知道脚本语言,这应该是非常简单的事情,而不需要我花3个小时去学习脚本。
@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
svnlook log %REPOS% -t %TXN% | findstr .......... > nul
VisualSVNServerHooks.exe check-logmessage
预提交钩子,在%VISUALSVN_SERVER%bin
目录下找到。这个简单的工具将帮助你定义日志信息中最少允许的字符数量。它还允许您执行以下操作:
svn cp
添加目录,但不能提交任何更改。这非常适合用于 /tags
目录,您可以在其中创建标记,但不能修改标记。它还允许您执行以下操作:
svn:ignore
,以便用户不会意外提交不应该提交的文件。svn:log
必须匹配某些正则表达式。此预提交脚本是用Perl编写的。默认情况下,Perl随Unix、Mac和Linux服务器一起提供。不幸的是,它没有包含在Windows计算机中。幸运的是,有几个开源、免费且易于安装的Perl软件包可用于PC,例如ActivePerl和Strawberry Perl。
试试这个:
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