In Subversion, when you commit the changeset, you're not allow to edit the log message but the SVN admin with svn-admin command.
To enable it to user, you (the SVN admin) must enable the pre-prop-change hook
pre-prop-change.bat (Windows)
Here is the content of pre-prop-change hook, just save it to pre-prop-change.bat and copy it into SVN hook folder. The content is Windows batch file and just for Windows environment
The script will enable the owner of the revision and the owner of SVN to change the log message.
The owner of SVN is get from SVN auth file (authz-svn.conf) and should be configure in the form @svn_owner = userA, userB...
You need to edit the PATH to authz-svn.conf file
@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
FOR /F "tokens=*" %%a IN ('svnlook author "%repository%" -r %revision%') DO set REV_USER=%%a
FOR /F "delims== tokens=1*" %%a IN (%repository%\..\Permission\authz-svn.conf) DO if "%%a"=="svn_owner " ( set SVN_OWNER=%%b )
set bIsOK=false
FOR %%a IN (%SVN_OWNER%) DO if "%%a"=="%userName%" ( set bIsOK=true )
if "%bIsOK%"=="false" (
goto ERROR_AUTHOR
)
goto :eof
:ERROR_AUTHOR
echo You must be the author of the log message or owner of the repository %SVN_OWNER% %userName%. >&2
goto ERROR_EXIT
: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-prop-change (Linux)
The following is the script in Linux, it just allow the owner of the revision to change the log.
#!/bin/sh
REPOS="$1"
REV="$2"
USER="$3"
PROPNAME="$4"
ACTION="$5"
if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:log" ];
then
REV_USER=`svnlook author "$REPOS" -r $REV`
if [ "$REV_USER" = "$USER" ];
then
exit 0;
else
echo "You must be the owner of the revision to be able to change the svn:log property" >&2
exit 1
fi
fi
echo "Changing revision properties other than svn:log is prohibited" >&2
exit 1
4 comments:
Didn't you forget to include %REV_USER% in the line following?
FOR %%a IN (%SVN_OWNER%) DO if "%%a"=="%userName%" ( set bIsOK=true )
Without it script didn't work with my VisualSVN Server, 1.6.3
@lynxnake, I'm not having any luck on VisualSVN Server either. Can you post a link to the fully revised script? Will this work if I am using Windows security?
@flipdoubt, seems that "error" was caused by different reason, SVN_OWNER in Hieu Le Trung's post was gotten by parsing ..\Permission\authz-svn.conf, which obviously is not present neither in VisualSVN, nor in average SVN setup.
I solved problem by simply setting up SVN_OWNER "by hands". Not a very good solution, but working.
Other changes:
- allowed author to be changed
- changed messages to be more informative
- allowed addition of revprop (log message now), not only modification
Here it is:
:: Thanks to Hieu Le Trung http://changetheworldwithyourpassion.blogspot.com/
@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 and author to be changed, but not else.
if /I "%propertyName%" == "svn:log" goto PROPERTY_NAME_OK
if /I "%propertyName%" == "svn:author" goto PROPERTY_NAME_OK
goto ERROR_PROPNAME
:PROPERTY_NAME_OK
:: Only allow modification or addition, but not deletion.
if /I "%action%" == "m" goto ACTION_OK
if /I "%action%" == "a" goto ACTION_OK
goto ERROR_ACTION
:ACTION_OK
:: Make sure that the new revision property is not empty.
set bIsEmpty=true
for /f "tokens=*" %%g in ('find /V ""') do (
set bIsEmpty=false
)
if "%bIsEmpty%" == "true" goto ERROR_EMPTY
FOR /F "tokens=*" %%a IN ('svnlook author "%repository%" -r %revision%') DO set REV_USER=%%a
set SVN_OWNERS=HERE_GOES_LIST_OF_SPACE_SEPARATED_USERS_WHO_ARE_ALLOWED_TO_CHANGE_AUTHOR_REVPROP
set bIsOK=false
FOR %%a IN (%SVN_OWNERS%) DO if "%%a"=="%userName%" ( set bIsOK=true )
if "%bIsOK%"=="false" (
goto ERROR_AUTHOR
)
goto :eof
:ERROR_AUTHOR
echo You authorised as "%userName%". To change revision property, you must be either the author of the log message ("%REV_USER%") or one of repository maintainers ("%SVN_OWNERS%"). >&2
goto ERROR_EXIT
:ERROR_EMPTY
echo Empty revision properties are not allowed. >&2
goto ERROR_EXIT
:ERROR_PROPNAME
echo Tried to change "%propertyName%" property. Only changes to svn:log and svn:author are allowed. >&2
goto ERROR_EXIT
:ERROR_ACTION
echo Requested wrong action ("%action%"). Only modifications ("m") and additions ("d") are allowed. >&2
goto ERROR_EXIT
:ERROR_EXIT
exit /b 1
Post a Comment