用于评论长度的 Windows 预提交挂钩 Subversion

发布于 2024-07-21 05:12:05 字数 221 浏览 8 评论 0 原文

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

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

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?

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

久随 2024-07-28 05:12:05

这是一个 .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 个 .,而不仅仅是 1 个

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

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

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

 @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

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

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

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

╰ゝ天使的微笑 2024-07-28 05:12:05

我使用 SubversionNotify,它的功能可能超出您的需要,但设置起来非常简单。

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

梦冥 2024-07-28 05:12:05

我有一个预提交挂钩,它可以完全满足您的需求。 还有更多。

  • 您可以指定提交注释的最小长度。
  • 您可以将提交评论与正则表达式进行匹配。 您不仅可以指定长度,还可以指定某些参数。 例如,提交注释是否包含缺陷跟踪系统使用的错误号,以便您可以追溯到特定缺陷的更改?

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

  • 针对特定文件或目录设置各种提交权限:
    • 读写:用户可以签出并提交这些项目。
    • 只读:用户可以签出此项目,但无法提交更改。
    • 仅添加:用户可以通过svn cp添加目录,但不能提交任何更改。 这非常适合 /tags 目录,您可以在其中创建标签,但不能修改标签。
    • 不删除:用户可以提交更改并添加新文件,但不能删除这些文件。
    • 无添加:用户只能提交更改,而不能在提交中添加或删除文件。

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

  • 通过 globbing
  • 要求某些文件或目录将特定属性设置为特定值。 对于确保 Unix shell 脚本、Unix Makefile 和 Windows Batch 文件具有正确的行结尾或设置 svn:ignore 等事情非常有用,这样用户就不会意外提交他们应该提交的文件。 t 提交。
  • 要求将某些修订属性设置为某些值。 这是检查提交消息的方式,但要求 svn:log 必须匹配某些正则表达式。

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

I have a pre-commit hook that 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 /tags directory 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.

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:ignore is 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:log must match certain regular expressions.

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 ActivePerl and Strawberry Perl

感情旳空白 2024-07-28 05:12:05

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

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

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

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

独木成林 2024-07-28 05:12:05

尝试这个 :

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  

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  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文