我似乎对此一无所获。要么在网上搜索脚本等。任何人都有一个脚本,你可以在 Windows 环境中编辑开箱即用的 pre-commit.tmpl,需要输入 x 字符才能评论 Tortoise Subversion 中的提交全局,以便团队中的所有成员都需要,而此要求从 SVN 服务器下推到客户端?
我不知道脚本语言,这应该是非常简单的事情,无需我花时间在接下来的 3 小时内弄清楚脚本。
我似乎对此一无所获。要么在网上搜索脚本等。任何人都有一个脚本,你可以在 Windows 环境中编辑开箱即用的 pre-commit.tmpl,需要输入 x 字符才能评论 Tortoise Subversion 中的提交全局,以便团队中的所有成员都需要,而此要求从 SVN 服务器下推到客户端?
我不知道脚本语言,这应该是非常简单的事情,无需我花时间在接下来的 3 小时内弄清楚脚本。
这是一个需要注释的 .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
findstr 命令的更高级选项将让您进行更高级的检查(某些字符集等)
我使用SubversionNotify,它可能比您需要的更多,但设置起来非常简单。
我有一个预提交钩子,可以完全按照您的意愿行事。再加上很多。
它还允许您执行以下操作:
svn cp
,但不能提交任何更改。/tags
这对于允许您制作标签但不能修改标签的目录来说是完美的。而且,它还允许您这样做:
svn:ignore
已设置等事情非常有用,因此用户不会意外提交不应提交的文件。svn:log
必须与某些正则表达式匹配。这个预提交脚本是用 Perl 编写的。默认情况下,Perl 带有 Unix、Mac 和 Linux 服务器。不幸的是,它不包含在 Windows 计算机上。幸运的是,有几个开源、免费且易于安装 PC 的 Perl 包,例如ActivePerl和Strawberry Perl
在 Windows 上,您可以使用VisualSVNServerHooks.exe check-logmessage
VisualSVN Server 附带的预提交挂钩,该挂钩位于%VISUALSVN_SERVER%bin
目录中。这个简单的工具将帮助您定义日志消息中允许的最小字符数。
有关说明,请参阅文章KB140:验证 VisualSVN 服务器中的提交日志消息。
试试这个 :
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