用于注释长度的 Windows 预提交钩子 Subversion

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/869248/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:21:33  来源:igfitidea点击:

Windows Pre-commit hook for comment length Subversion

windowssvntortoisesvnsvn-hookspre-commit

提问by PositiveGuy

I seem to be getting nowhere with this. Either searching the web for a script, etc. Anyone got a script that you can just edit the out-of-box pre-commit.tmpl in a Windows environment that requires x chars to be entered in for a comment on commit in Tortoise Subversion globally so that all members on the team are required whereas this requirement is pushed down to the clients from SVN server?

我似乎无处可去。要么在网上搜索脚本等。任何人都得到了一个脚本,您可以在需要输入 x 个字符的 Windows 环境中编辑开箱即用的 pre-commit.tmpl 以在 Tortoise Subversion 中对提交进行评论全局,以便团队中的所有成员都是必需的,而此要求从 SVN 服务器推送到客户端?

I don't know the scripting language and this should be something pretty damn simple without me taking the time to figure out scripting for the next 3 hours.

我不知道脚本语言,这应该是非常简单的事情,我不需要花时间在接下来的 3 小时内弄清楚脚本。

回答by Corey Downie

This is a .bat file to require there is a comment. It checks for the existence of at least one character in the comment.

这是一个 .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

This file sits in the /hooks folder of the repository, named pre-commit.bat. If you need a minimum amount of characters, the line to modify is

该文件位于存储库的 /hooks 文件夹中,名为 pre-commit.bat。如果您需要最少的字符数,则要修改的行是

svnlook log %REPOS% -t %TXN% | findstr . > nul

So if you wanted a minimum of 10 characters, you need to have 10 .'s rather than just one

因此,如果您想要至少 10 个字符,则需要有 10 个 . 而不是一个

svnlook log %REPOS% -t %TXN% | findstr .......... > nul

More advanced options for the findstrcommand will let you do fancier checks (certain character sets, ect)

findstr命令的更多高级选项将让您进行更高级的检查(某些字符集等)

回答by Slipfish

I use SubversionNotify, it probably does more than what you need, but is pretty simple to set up.

我使用SubversionNotify,它可能比您需要的更多,但设置起来非常简单。

回答by Nick

Try this :

尝试这个 :

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  

回答by David W.

I have a pre-commit hookthat can do exactly what you want. Plus a lot more.

我有一个预提交钩子,可以做你想做的事。还有很多。

  • You can specify a minimum length of commit comment.
  • You can match the commit comment against a regular expression. Not only can you specify a length, but you can also specify certain parameters. For example, does the commit comment contain a bug number that your defect tracking system uses, so you can trace back the change to a particular defect?
  • 您可以指定提交注释的最小长度。
  • 您可以将提交注释与正则表达式进行匹配。您不仅可以指定长度,还可以指定某些参数。例如,提交注释是否包含缺陷跟踪系统使用的错误编号,以便您可以将更改追溯到特定缺陷?

It also allows you to do the following:

它还允许您执行以下操作:

  • Set various commit permissions against particular files or directories:
    • read-write: User can checkout and commit these items.
    • read-only: User can checkout this item, but can't commit changes.
    • add-only: User can add a directory via svn cp, but not commit any changes. This is perfect for the /tagsdirectory where you are allowed to make a tag, but not modify the tag.
    • no-delete: Users can commit changes and add new files, but not delete these files.
    • no-add: Users can only commit changes, and not add or delete files in a commit.
  • 针对特定文件或目录设置各种提交权限:
    • 读写:用户可以签出和提交这些项目。
    • 只读:用户可以签出此项,但不能提交更改。
    • add-only:用户可以通过添加目录svn cp,但不能提交任何更改。这对于/tags您可以创建标签但不能修改标签的目录来说是完美的。
    • no-delete:用户可以提交更改并添加新文件,但不能删除这些文件。
    • no-add:用户只能提交更改,不能在提交中添加或删除文件。

And, it also allows you to do this:

而且,它还允许您执行以下操作:

  • Ban certain file names via regular expressions of globbing,
  • Require certain files or directories have a particular property set to a particular value. Very useful for things like making sure Unix shell scripts, Unix Makefiles, and Windows Batch files have the correct line ending, or svn:ignoreis set, so users don't accidentally commit in files they shouldn't commit.
  • Require certain revisions properties to be set with certain values. This is how you check commit messages, but saying that svn:logmust match certain regular expressions.
  • 通过通配符的正则表达式禁止某些文件名,
  • 要求某些文件或目录具有设置为特定值的特定属性。对于确保 Unix shell 脚本、Unix Makefile 和 Windows Batch 文件具有正确的行尾或svn:ignore设置等非常有用,因此用户不会意外地提交不应该提交的文件。
  • 需要使用某些值设置某些修订属性。这就是您检查提交消息的方式,但说svn:log必须匹配某些正则表达式。

This pre-commit script is written in Perl. By default, Perl comes with Unix, Mac, and Linux servers. Unfortunately, it isn't included on Windows computers. Fortunately, there are several open source, free, and easy to install Perl packages for the PC such as ActivePerland Strawberry Perl

这个预提交脚本是用 Perl 编写的。默认情况下,Perl 带有 Unix、Mac 和 Linux 服务器。不幸的是,它不包含在 Windows 计算机上。幸运的是,有几个开源、免费且易于安装的用于 PC 的 Perl 包,例如ActivePerlStrawberry Perl

回答by bahrep

On Windows, you can use the VisualSVNServerHooks.exe check-logmessagepre-commit hook that comes with VisualSVN Server and is located in the %VISUALSVN_SERVER%bindirectory. This simple tool will help you define the minimum allowed number of characters in the log message.

在 Windows 上,您可以使用VisualSVNServerHooks.exe check-logmessageVisualSVN Server 附带的预提交钩子,位于%VISUALSVN_SERVER%bin目录中。这个简单的工具将帮助您定义日志消息中允许的最小字符数。

See the article KB140: Validating commit log messages in VisualSVN Serverfor instructions.

有关说明,请参阅文章KB140:在 VisualSVN 服务器中验证提交日志消息