Wednesday, November 21, 2012

To amend the commit message on SVN under Windows

Another concern on using SVN as source version control is when programmer did something wrong with the commit message. In order to allow amendment on the commit message, I am required to have pre-revprop-change hook script ready.

Doing it in Windows always have extra steps. Save a copy of this pre-revprop-change template file locate under the /hooks directory into .bat extension, replace the code with the one I got from this article. What a nice and clean code.

:: 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

echo Empty svn:log messages are not allowed. >&2

echo Only changes to svn:log messages are allowed. >&2

echo Only modifications to svn:log revision properties are allowed. >&2

exit /b 1

Done with first step, now come to second step, is to edit the commit message or adding a commit message. If the commit message is already there, use this command to remote access the SVN server to modify the commit message.
svn propedit --revprop -r 25 svn:log \ "Update a commit message." \
--editor-cmd notepad.exe
This is to tell SVN that I'm going to update the commit message on revision 25 where the particular file is located at directory using notepad as editor.

If --editor-cmd is not provided, this will assume that the SVN_EDITOR environment variable has been set, otherwise an error will be prompt "None of the environment variables SVN_EDITOR, VISUAL or EDITOR are set...".

If the commit message isn't there, then use this command to add a new commit message.
svn propset -r 25 --revprop svn:log \
"new log message"

This is to tell SVN that I'm going to add a new commit message on revision 25 where the particular file is located at directory

No comments: