35

我做了一点谷歌搜索,发现实际上并没有适用于 Windows 的 SVN 挂钩资源。所以我想我会在这里建立一个维基来集中它。

如果您投稿,请务必注明:

  1. 钩子的名字
  2. 脚本的作用
  3. 实际脚本

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

4

9 回答 9

11

防止带有空注释的提交

  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
于 2009-03-11T07:19:41.510 回答
8

防止编辑除 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
于 2009-03-11T07:10:53.217 回答
6

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

将提交信息发布到 Twitter

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

使用说明:

  • twitterUsernametwitterPassword替换为您的实际 Twitter
  • 这是针对 VisualSVN 进行测试的,我可以让它工作的唯一方法是将所有内容转储到硬编码路径c:\hook\post-commit中。您可以将其更改为 VisualSVN 具有读/写访问权限的任何路径。
  • 需要安装 Wget。安装程序可以在这里下载
  • 欢迎评论和改进。这是我在 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
于 2010-03-04T04:55:13.617 回答
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

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

等等等等等等

于 2009-10-20T15:52:53.770 回答
4

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

预提交:

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

提交后:

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

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

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

于 2011-12-08T22:32:16.957 回答
3

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

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

该项目托管在Source Forge

于 2009-03-11T07:28:44.860 回答
3

防止编辑除 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
于 2009-06-04T14:30:20.577 回答
1

I started a repository of hooks using C#. My first hook was one to send check in notices to a RSS feed: SubversionRss I'm currently working on one post-commit hook to send check in notices to a Twitter feed.

于 2009-03-19T17:31:36.337 回答
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
于 2016-07-04T14:29:54.573 回答