什么是SVN中的pre-revprop变更挂钩,如何创建它?
我想在存储库浏览器中编辑日志注释,收到一条错误消息,表示存储库不存在pre-revprop change hook。除了有一个可怕的名字外,什么是pre-revprop change hook,我该如何创建它?基本上,它是一个在存储库上修改unversioned属性之前启动的脚本,因此您可以更精确地管理存储库上发生的事情什么是SVN中的pre-revprop变更挂钩,如何创建它?,svn,svn-hooks,Svn,Svn Hooks,我想在存储库浏览器中编辑日志注释,收到一条错误消息,表示存储库不存在pre-revprop change hook。除了有一个可怕的名字外,什么是pre-revprop change hook,我该如何创建它?基本上,它是一个在存储库上修改unversioned属性之前启动的脚本,因此您可以更精确地管理存储库上发生的事情 @ECHO OFF :: Set all parameters. Even though most are not used, in case you want to add
@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
SVN发行版中有用于不同钩子的模板,位于/hooks子目录(*.tmpl)中,您必须根据操作系统对其进行编辑和重命名才能激活该模板。对于Windows,这里有一个指向示例批处理文件的链接,该文件只允许更改日志消息(而不允许更改其他属性): 基本上,将下面的代码复制到一个文本文件中,将其命名为
pre revprop change.bat
,并将其保存在存储库的\hooks
子目录中
@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
下面是指向堆栈溢出问题的链接,其中有许多常见的钩子,包括此处交叉发布的
pre-revprop change
hook for Windows的原始来源
您应该参考这些内容,因为它们可能会随着时间的推移而改进。对于PC用户:
.bat扩展在Windows Server计算机上使用时对我不起作用。我按照Django Reinhardt的建议使用了VisualSvn,它创建了一个带有.cmd扩展名的钩子。谢谢#patmortech
我添加了你的代码,“只有同一个用户可以更改他的代码”
如果您设法破译钩子脚本,它的名称就不会那么可怕了:它是修订前属性更改钩子。简言之,hook脚本的目的是控制未版本(修订)属性的更改并发送通知(例如,在修订属性更改时发送电子邮件) Subversion中有两种类型的属性:
- 可在文件和目录上设置的版本化属性(例如
和svn:needs lock
)svn:mime type
- 在存储库版本上设置的未版本化(修订)属性(例如
和svn:log
)svn:date
svn:date
、用户名的svn:author
和提交日志消息的svn:log
(如果您指定了)
正如我已经指定的那样,pre-revprop change
hook脚本的目的是控制修订属性的更改。您不希望每个有权访问存储库的人都能够修改所有修订属性,因此默认情况下禁止更改修订属性。要允许用户更改属性,必须创建pre-revprop change
hook
最简单的钩子只能包含一行:exit 0
。它将允许任何经过身份验证的用户更改任何修订属性,并且不应在实际环境中使用它。在Windows上,您可以使用批处理脚本或基于PowerShell的脚本在pre-revprop change
hook中实现一些逻辑
此PowerShell脚本仅允许更改svn:log
属性,并拒绝空日志消息
# Store hook arguments into variables with mnemonic names
$repos = $args[0]
$rev = $args[1]
$user = $args[2]
$propname = $args[3]
$action = $args[4]
# Only allow changes to svn:log. The author, date and other revision
# properties cannot be changed
if ($propname -ne "svn:log")
{
[Console]::Error.WriteLine("Only changes to 'svn:log' revision properties are allowed.")
exit 1
}
# Only allow modifications to svn:log (no addition/overwrite or deletion)
if ($action -ne "M")
{
[Console]::Error.WriteLine("Only modifications to 'svn:log' revision properties are allowed.")
exit 2
}
# Read from the standard input while the first non-white-space characters
$datalines = ($input | where {$_.trim() -ne ""})
if ($datalines.length -lt 25)
{
# Log message is empty. Show the error.
[Console]::Error.WriteLine("Empty 'svn:log' properties are not allowed.")
exit 3
}
exit 0
此批处理脚本仅允许“svnmgr”用户更改修订属性:
IF "%3" == "svnmgr" (goto :label1) else (echo "Only the svnmgr user may change revision properties" >&2 )
exit 1
goto :eof
:label1
exit 0
Linux允许编辑日志注释
- 在存储库的
目录中找到文件hooks
pre revprop change.tmpl
- 将文件复制到同一目录,并将其重命名为
pre revprop change
- 为文件授予执行权限(对于服务器用户,例如
)www-data
- 之后,您可能需要编辑脚本,以针对您希望允许的编辑类型返回退出值
0
(此解决方案肯定有缺点,因为没有检查/禁止任何内容。但就我而言,只有我在使用的本地回购协议似乎有效。)这是我在Windows服务器上最容易做到的: 在VisualSVN中,右键单击您的存储库,然后选择属性…,然后选择挂钩选项卡 选择修订前属性更改挂钩,单击编辑 我需要能够更改作者-这经常发生在由多人使用的远程计算机上,即我们错误地使用其他人存储的凭据签入 以下是要粘贴的修改后的社区wiki脚本:
@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 author to be changed, but not message ("svn:log"), etc.
if /I not "%propertyName%" == "svn:author" 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:author messages are not allowed. >&2
goto ERROR_EXIT
:ERROR_PROPNAME
echo Only changes to svn:author messages are allowed. >&2
goto ERROR_EXIT
:ERROR_ACTION
echo Only modifications to svn:author revision properties are allowed. >&2
goto ERROR_EXIT
:ERROR_EXIT
exit /b 1
如果要保存日志消息上的更改,请使用上面@patmortech()中答案中的批处理脚本,
谁从中复制了脚本,
并在“%bismempty%”==“true”转到错误\u EMPTY和
goto:eofbefore
之间添加这些行:
set outputFile=%repos%\log-change-history.txt
echo User '%user%' changes log message in rev %rev% on %date% %time%.>>%outputFile%
echo ----- Old message: ----->>%outputFile%
svnlook propget --revprop %repos% svn:log -r %rev% >>%outputFile%
echo.>>%outputFile%
echo ----- New message: ----->>%outputFile%
for /f "tokens=*" %%g in ('find /V ""') do (echo %%g >>%outputFile%)
echo ---------->>%outputFile%
echo.>>%outputFile%
它将在服务器上的repo文件夹中创建一个文本文件
log change history.txt
,并附加每个日志更改通知。可能已链接到那里的版本。我写了那个钩子,不久前在SVN论坛上发布了它。我想我应该在钩子注释中添加一些注释。我正在将此脚本与VisualSVN 2.0.8和TortoiseSVN 1.6.11一起使用,效果很好。您可以在VisualSVN服务器中右键单击存储库名称并选择“属性…”来编辑VisualSVN中的钩子。您将看到一个“挂钩”选项卡。在这里,您将看到不同类型的可用挂钩。选择右边的一个,点击“编辑”并将上面的代码粘贴到其中。希望对VisualSVN用户有所帮助!工作f