@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
:: 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
最简单的钩子可以只包含一行: exit 0。它允许任何经过身份验证的用户更改任何修订属性,并且不应该在实际环境中使用。在 Windows 上,可以使用批处理脚本或基于 PowerShell 的脚本在 pre-revprop-change钩子中实现某些逻辑。
此 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
这对我来说是 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