subversion pre-revprop-change.bat
windows环境下利用hooks下的pre-revprop-change.bat实现以下功能:
1、只允许用户修改自己的日志。
2、只允许对日志进行操作,不允许对其它属性操作,例如作者。
3、只允许对日志进行修改,不允许增加、删除日志。
4、设置超级用户,超级用户可以修改、增加、删除其他人的日志。
脚本如下:
@ECHO OFF
set repos=%1
set rev=%2
set user=%3
set propname=%4
set action=%5
//设置超级用户,超级用户可以修改其他人的日志,其他人只能修改自己的日志
set superUser=username
//只允许日志svn:log的修改
if /I not '%propname%'=='svn:log' goto ERROR_PROPNAME
//只允许修改日志,增加、删除等操作不允许
if /I not '%action%'=='M' goto ERROR_ACTION
//只允许用户修改自己的日志
for /f "usebackq" %%k in (`svnlook author %repos% -r %rev%`) do @set var=%%k
set rightUser=0
if "%3" == "%superUser%" set rightUser=1
if "%3" == "%var%" set rightUser=1
if %rightUser% == 0 goto ERROR_USER
goto :SUCCESS_EXIT
:ERROR_USER
echo 只允许用户修改自己的日志 >&2
goto ERROR_EXIT
:ERROR_PROPNAME
echo 只有日志信息能被修改 >&2
goto ERROR_EXIT
:ERROR_ACTION
echo 只允许修改日志,不允许增加、删除等操作 >&2
goto ERROR_EXIT
:ERROR_EXIT
exit 1
:SUCCESS_EXIT
exit 0
------------------------------------------------------------
JIRA的svn插件是个好用的工具,但是之前提交的svn:log没有记录FIX哪些bug的记录,编辑svn:log需要加入如下hook。
即使修改了历史svn:log,svn plugin并不会重新读取这些svn:log ,-_-! 可能需要重新扫描一遍,如何操作?
http://svn.haxx.se/users/archive-2006-03/0107.shtml
Hi all,
Here I post a pre-revprop-change batch file for Windows NT or later... You
can certainly enhance it with more modifications. You can also derive a
post-revprop-change.cmd from it to backup the old 'snv:log' somewhere...
The only tricky part there was to be able to actually parse the stdin from
the batch file... This is done here with the FIND.EXE command.
Enjoy:
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~ ~ ~ ~
@ECHO OFF
set repos=%1
set rev=%2
set user=%3
set propname=%4
set action=%5
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Only allow changes to svn:log. The author, date and other revision
:: properties cannot be changed
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if /I not '%propname%'=='svn:log' goto ERROR_PROPNAME
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Only allow modifications to svn:log (no addition/overwrite or deletion)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if /I not '%action%'=='M' goto ERROR_ACTION
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Make sure that the new svn:log message contains some text.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
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 properties are not allowed. >&2
goto ERROR_EXIT
:ERROR_PROPNAME
echo Only changes to svn:log revision properties 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
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~ ~ ~ ~