我想在代码库浏览器中编辑日志注释,但是收到了一个错误消息,指出该代码库不存在“pre-revprop-change”钩子。除了名称有点可怕之外,“pre-revprop-change”钩子是什么,我该如何创建它?
针对Windows操作系统,这里有一个示例批处理文件的链接,该文件只允许更改日志信息而不允许更改其他属性:
http://ayria.livejournal.com/33438.html
将下面的代码复制到一个文本文件中,并将其命名为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
3.5.6
和TortoiseSVN 1.9.4
中仍然有效。 - Enigma基本上,这是一个在未版本化属性在存储库上被修改之前启动的脚本,以便您可以更精确地管理存储库上正在发生的情况。
在SVN分发中有不同挂钩的模板,位于/hooks子目录中(*.tmpl),您需要根据您的操作系统进行编辑和重命名才能激活。
svnsync
镜像的钩子,则默认脚本需要更改,因为它只允许更改 svn:log。Svnsync 更改的不止这些,所以我只是在那里放了一个 exit 0
,以允许所有属性更改(因为这只是我的镜像)。 - Matt Connollypre-revprop-change
到同一目录,并使其对 Web 服务器用户(在 Linux 上)可执行。 - Mateng为了允许在Linux中编辑日志注释:
hooks
目录中的pre-revprop-change.tmpl
文件。pre-revprop-change
。www-data
)。编辑:(感谢lindes)
0
的退出值,以允许您想要进行的编辑类型。这里是一个包含许多常见钩子的堆栈溢出问题链接Common Types of Subversion Hooks,其中包括Windows平台下pre-revprop-change
钩子的原始源代码,该内容被转载到此处。
您应该参考那里的内容,因为它们可能随着时间的推移而得到改进。
感谢 #patmortech
我添加了你的代码,它可以实现“只有同一用户才能更改他的代码”的功能。
:: Only allow editing of the same user.
for /f "tokens=*" %%a in (
'"%VISUALSVN_SERVER%\bin\svnlook.exe" author -r %revision% %repository%') do (
set orgAuthor=%%a
)
if /I not "%userName%" == "%orgAuthor%" goto ERROR_SAME_USER
pre-revprop-change
钩子脚本的目的是控制未版本化(修订)属性的更改,并发送通知(例如,在修订属性更改时发送电子邮件)。svn:needs-lock
和 svn:mime-type
),可以设置在文件和目录上,
- 未版本化(修订)属性(例如 svn:log
和 svn:date
),设置在仓库的修订上。svn:date
,其值为您提交的 UTC 时间,svn:author
的值为您的用户名,svn:log
的值为您的提交日志消息(如果您指定了任何)。pre-revprop-change
钩子脚本的目的是控制修订属性的更改。您不希望每个具有访问仓库权限的人都能够修改所有修订属性,因此默认情况下禁止更改修订属性。要允许用户更改属性,必须创建 pre-revprop-change
钩子。exit 0
。它将允许任何经过身份验证的用户更改任何修订属性,并且不应在真实环境中使用。在 Windows 上,您可以使用批处理脚本或基于 PowerShell 的脚本来在 pre-revprop-change
钩子中实现一些逻辑。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
IF "%3" == "svnmgr" (goto :label1) else (echo "Only the svnmgr user may change revision properties" >&2 )
exit 1
goto :eof
:label1
exit 0
if "%bIsEmpty%" == "true" goto ERROR_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%
log-change-history.txt
,并追加每个日志更改通知。(这种解决方案当然有缺陷,因为没有任何检查/禁止。但对于我这种只使用本地仓库的情况来说,它似乎可以工作。)
@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
对于PC用户: 当我在Windows Server上使用.bat扩展名时,它并没有起作用。正如Django Reinhardt所建议的那样,我使用了VisualSvn,并创建了一个带有.cmd扩展名的钩子。