【问题标题】:SVN hooks for Windows适用于 Windows 的 SVN 挂钩
【发布时间】:2009-03-11 07:09:49
【问题描述】:

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

如投稿,请务必注明:

  1. 挂钩的名称
  2. 脚本的作用
  3. 实际脚本

注意:我怀疑发布史诗脚本不会有用。

【问题讨论】:

标签: svn repository svn-hooks


【解决方案1】:

防止使用空 cmets 提交

  1. 预提交
  2. 防止带有空注释的提交

来源:

"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

【讨论】:

    【解决方案2】:

    防止对除 svn::log 之外的版本属性进行编辑

    1. pre-revprop-change.bat
    2. 防止对 svn::log 以外的修订属性进行编辑

    @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
    

    【讨论】:

    • 大声感谢您的编辑。我真的在为降价而苦苦挣扎
    【解决方案3】:

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

    将提交信息发布到 Twitter

    1. 挂钩的名称 = 提交后
    2. 脚本的作用 = 将修订、作者和提交消息发布到 Twitter

    使用说明:

    • twitterUsernametwitterPassword 替换为您的实际 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
    

    【讨论】:

    • 看起来这行不通 - Twitter 是否更改了其身份验证方法?
    • @gt 是的,有。仅现在 OAuth;没有用户名和密码了。我会更新的。
    • 可惜,看起来是个不错的实用工具!
    【解决方案4】:

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

    1. 挂钩的名称 = 预提交
    2. 脚本的作用 = 检查空行或“.”线。还要检查一个不允许作为唯一注释的单词文件。

    实际脚本

    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
    

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

    等等等等等等等等

    【讨论】:

      【解决方案5】:

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

      预提交:

      • 强制提交消息要求,或最小长度或两者(或不)
      • 可以在提交消息中强制执行 RegEX 表达式要求,适用于要求积压或缺陷编号(或不要求)

      提交后:

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

      你可以在谷歌代码@http://code.google.com/p/subhooker/找到它

      它是免费的,是的,我是作者,我已经运行 subversion 几年了,我非常喜欢它,这就是我将其回馈给社区的原因。

      【讨论】:

        【解决方案6】:

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

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

        项目托管在Source Forge

        【讨论】:

        • 不,我非常渴望在我以前的工作中使用它来处理我们在源代码管理中管理配置文件时遇到的一些问题,但它在我的 TODO 列表中从来没有足够高。这些天我个人可能对使用 perl 脚本更感兴趣。
        • 我目前正在和 CaptainHook 一起玩。确保获取补丁文件 - 它修复了 2x 错误
        • 我没有尝试过 CaptainHook,但是链接页面上所有最新的 cmets 报告它已损坏并且所有有用的功能都被注释掉(并且不会编译)。作者说他会尝试修复它,但那是在 2007 年。看起来最好避开这个问题。
        【解决方案7】:

        防止对除 svn::log 之外的版本属性进行编辑

        1. pre-revprop-change.bat
        2. 防止对 svn::log 以外的修订属性进行编辑(替代版本)

        来源:

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

        【讨论】:

          【解决方案8】:

          我使用 C# 启动了一个钩子存储库。我的第一个挂钩是将签入通知发送到 RSS 提要:SubversionRss 我目前正在开发一个提交后挂钩,以将签入通知发送到 Twitter 提要。

          【讨论】:

            【解决方案9】:

            这个钩子防止提交到特定的分支

            (在这种情况下为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
            

            【讨论】:

              猜你喜欢
              • 2015-04-22
              • 1970-01-01
              • 2021-12-18
              • 2012-06-08
              • 2015-12-03
              • 2011-10-23
              • 1970-01-01
              • 1970-01-01
              • 2021-12-23
              相关资源
              最近更新 更多