适用于Windows的SVN挂钩

时间:2009-03-11 07:09:50

标签: svn repository svn-hooks

我做了一点谷歌搜索,发现没有真正的Windows资源SVN挂钩。所以我想我会在这里开始一个wiki来集中它。

如果您贡献,请务必注明:

  1. 钩子的名称
  2. 脚本的作用
  3. 实际脚本
  4. 注意:我怀疑发布一个史诗脚本是没用的。

9 个答案:

答案 0 :(得分:11)

使用空注释阻止提交

  1. 预提交
  2. 阻止提交空评论
  3. 来源:

    "c:\Program Files\Subversion\bin\svnlook.exe" log -t %2 %1 | FindStr [a-zA-Z0-9]
    IF %ERRORLEVEL% EQU 0 GOTO OK
    echo "Commit Comments are Required" >&2
    exit 1
    :OK
    exit 0
    

答案 1 :(得分:8)

防止编辑除svn :: log

以外的修订道具
  1. 的pre-revprop-change.bat
  2. 防止编辑除svn :: log
  3. 以外的修订属性

    @ECHO OFF
    :: Set all parameters. Even though most are not used, in case you want to add
    :: changes that allow, for example, editing of the author or addition of log messages.
    set repository=%1
    set revision=%2
    set userName=%3
    set propertyName=%4
    set action=%5
    
    :: Only allow the log message to be changed, but not author, etc.
    if /I not "%propertyName%" == "svn:log" goto ERROR_PROPNAME
    
    :: Only allow modification of a log message, not addition or deletion.
    if /I not "%action%" == "M" goto ERROR_ACTION
    
    :: Make sure that the new svn:log message is not empty.
    set bIsEmpty=true
    for /f "tokens=*" %%g in ('find /V ""') do (
    set bIsEmpty=false
    )
    if "%bIsEmpty%" == "true" goto ERROR_EMPTY
    
    goto :eof
    
    :ERROR_EMPTY
    echo Empty svn:log messages are not allowed. >&2
    goto ERROR_EXIT
    
    :ERROR_PROPNAME
    echo Only changes to svn:log messages are allowed. >&2
    goto ERROR_EXIT
    
    :ERROR_ACTION
    echo Only modifications to svn:log revision properties are allowed. >&2
    goto ERROR_EXIT
    
    :ERROR_EXIT
    exit /b 1
    

答案 2 :(得分:6)

*更新:这已不再适用,因为Twitter已弃用用户名/密码身份验证而支持OAuth。 *

将提交信息发布到Twitter

  1. hook的名称= post-commit
  2. 脚本的作用=将修订,作者和提交消息发布到Twitter
  3. 使用说明:

    • twitterUsername twitterPassword 替换为您的实际Twitter
    • 这是针对VisualSVN进行测试的,我能让它工作的唯一方法是将所有内容转储到硬编码路径 c:\ hook \ post-commit 。您可以将其更改为VisualSVN具有读/写访问权限的任何路径。
    • 需要安装Wget。安装程序可以下载here
    • 欢迎评论和改进。这是我在Windows上的第一个SVN钩子,我的GAWD很痛苦。

    实际脚本

    echo status= > c:\hook\post-commit\msg.txt
    echo Rev#%2 by >> c:\hook\post-commit\msg.txt
    "%VISUALSVN_SERVER%\bin\svnlook.exe" author -r %2 %1 >> c:\hook\post-commit\msg.txt
    "%VISUALSVN_SERVER%\bin\svnlook.exe" log -r %2 %1 >> c:\hook\post-commit\msg.txt
    "c:\Program Files (x86)\GnuWin32\bin\wget.exe" --user=twitterUsername --password=twitterPassword --post-file=c:\hook\post-commit\msg.txt --append-output=c:\hook\post-commit\log.txt --output-document=c:\hook\post-commit\download.txt --delete-after http://twitter.com/statuses/update.xml
    

答案 3 :(得分:4)

检查常见的“懒惰”提交消息

  1. hook = pre-commit
  2. 的名称
  3. 脚本的作用=检查空白行或“。”线。同时检查不允许作为唯一评论的文字文件。
  4. 实际脚本

    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 Check if comment is in list of reserved words to not be used..
    
    "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 Check that the author of this commit has the rights to perform
    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
    

    示例排除的单词文件: 更新 更新 更新。 更新。 固定 固定 固定。 固定。 .. 。 ... 。 。   。  。 分类 排序。 排序 排序

    等等等等

答案 4 :(得分:4)

我喜欢使用以java编码的subHooker。 它提供了前提交和后提交挂钩功能。

预提交:

  • 强制提交邮件要求,或最小长度或两者兼有(或不是)
  • 可以在提交消息中强制执行RegEX表达式要求,适用于要求返回日志或缺陷号(或不是)

提交后:

  • 发送HTML或纯文本电子邮件
    • 普通和html消息都使用模板系统
    • 可以打开或关闭差异
    • 可以打开或关闭更改设置
  • 支持本地化
  • 支持标准化日志记录。

您可以在Google代码@ http://code.google.com/p/subhooker/

上找到它

它是免费的,是的,我是作者,我已经运行颠覆几年了,我很喜欢它,这就是为什么我要回馈社区。< / p>

答案 5 :(得分:3)

对于在Windows上使用Subversion的.NET开发人员,Phil Haack发布了CaptainHook

  

CaptainHook是一个简单的插件   用于编写Subversion钩子的框架   使用.NET

该项目位于Source Forge

答案 6 :(得分:3)

防止编辑除svn :: log

以外的修订道具
  1. 的pre-revprop-change.bat
  2. 防止编辑除svn :: log(备用版本)
  3. 以外的修订版属性

    来源:

    rem Only allow log messages to be changed.
    if "%4" == "svn:log" exit 0
    echo Property '%4' cannot be changed >&2
    exit 1
    

答案 7 :(得分:1)

我使用C#启动了一个钩子库。我的第一个钩子就是将登记通知发送到RSS提要:SubversionRss我正在处理一个提交后挂钩,将登记通知发送到Twitter提要。

答案 8 :(得分:1)

此挂钩阻止了对特定分支的提交

(在这种情况下, branch-16E ):

setlocal

rem Subversion sends through the path to the repository and transaction id  
set REPOS=%1
set TXN=%2

rem Committing to a branch is not allowed
svnlook changed -t %TXN% %REPOS% | findstr "\/branch-16E"
if %errorlevel% EQU 0 goto errb else exit 0

:errb
echo. 1>&2
echo This branch was closed. If you want to commit here contact your administrator. 1>&2
exit 1