SVN pre-revprop-change hook scripts for Linux and Windows

Linux

For Linux it’s a simple shell script, nothing fancy is needed. If the script ends with a 0 exit value, the commit will work, if it exits non-zero, the commit will fail.

If the path (not an svn-path) to your repository on the server is /opt/myRepo/ then the pre-revprop-change script goes in /opt/myRepo/hooks/. You will find a bunch of templates for hooks in that directory. You need to make your script executable by the user your webserver runs as, because that’s who’s going to run this.

pre-revprop-change

#!/bin/sh
# Set up the list of possible parameters.
REPOS="$1"
REV="$2"
USER="$3"
PROPNAME="$4"
ACTION="$5"

# Allow log modifications
if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:log" ]; then
    exit 0
else
    echo "Changing revision properties other than svn:log is prohibited" >&2
    exit 1
fi

Windows

In Windows the syntax is different because you don’t have a real shell. Instead, you use batch file commands to accomplish the same thing. The logic is pretty much the same because it’s simple.

pre-revprop-change.bat

From http://tinyurl.com/68afroe

@ECHO OFF
:: Set up the list of possible parameters.
set repository=%1
set revision=%2
set userName=%3
set propertyName=%4
set action=%5 

:: Allow the log message itself to be changed.
if /I not "%propertyName%" == "svn:log" goto ERROR_PROPNAME 

:: Allow modification of a log message, not addition or deletion.
if /I not "%action%" == "M" goto ERROR_ACTION 

:: Make sure that the changed svn:log message is not null.
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
Posted by admica   @   8 January 2010

Related Posts

4 Comments

Comments
Nov 29, 2010
5:26 pm

Used the Windows script and it worked like a charm.

However, I notice that the %action% variable contained the value “M ” (M followed by a space) when I tried to modify the Repository Log Message, so I changed the following line:

[OLD] if /I not “%action%” == “M” goto ERROR_ACTION
[NEW] if /I not “%action%” == “M ” goto ERROR_ACTION

Other than that, it worked great. Thanks for the post.

Jun 15, 2011
6:40 pm
#2 Greg W :

I found that “exit /b 1″ was not working for me under XP. Subversion ran the script but ignored the return code. Removing /b so that it was “exit 1″ solved the issue.

Aug 6, 2011
5:12 am
#3 sophie :

This script is not working on windows 7 OS. Can you please help?

Dec 20, 2011
1:39 pm
#4 Neosys :

Same here Subversion Server installed on Windows 2008 server and client is Win7.
error is :
pre-revprop-change.bat’: The given path is misformatted or contained invalid characters

Leave a Comment

Name

Email

Website

*

Previous Post
«
Next Post
»
Powered by Wordpress   |   Lunated designed by ZenVerse

Valid XHTML 1.0 Transitional