Take the 2-minute tour ×

Found one of the useful SVN pre-commit hook in SVN pre-commit hook for avoiding changes to tags subdirectories by mcdon.

I want to add the validation check on the user before committing. Can I do something like below?

@echo off
REM  user1, user2, user3 are example
set VALID_USERS=user1,user2,user3

set SVNROOT="C:\Program Files\CollabNet Subversion Server\svnlook.exe"
set REPOS=%1%
set TXN=%2%

%SVNROOT% author %REPOS% -t %TXN% | findstr /r "^%VALID_USERS%$" >nul
if %errorlevel% EQU 0 (
   echo This is an invalid user 1>&2
   exit 1
) else (
   echo This is valid user 1>&2
   exit 0

The above pre-commit script failed as all users can commit their files. Also, the 'echo' command not working as I don't see any echo statement above. Can anyone help?

share|improve this question

2 Answers 2

Found the following solution working:

REM     Block deletion of folder/file in trunk
%SVNLOOK% changed %REPOS% -t %TXN% | findstr /r "^D.*trunk/.*$" >nul
if %errorlevel%==0 (goto DeleteInTrunkError)

REM     DeleteInTrunkError
echo. 1>&2
echo Trunk Delete Error: 1>&2
echo     Only Administrator can delete in the trunk folder. 1>&2
echo Commit details: 1>&2
%SVNROOT% changed %REPOS% -t %TXN% 1>&2
exit 1
share|improve this answer

I don't understand why you should want a pre-commit hook for that, so I give you a sketch what we are using when working on tags.

  1. We use the Subversion path-based authorization, and have rules like that:

    * = r
    @R_SVN_ADMINS = rw

    so only admins are allowed to create and modify tags.

  2. If necessary, we add for each tag a rule to avoid modification:

    @R_SVN_ADMINS = r
  3. An alternative solution is to modify the rules in the first point after creation, so that tags are only read-only.

This works for us because tags are created seldomly, and we don't have much of them. We don't need any hooks to forbid something ...

share|improve this answer
Thanks mliebelt for your response. I thought of using pre-commit hook to restrict user from deleting file/folder in the /trunk directory. –  tanlccc Nov 10 '11 at 8:43
Then you should rephrase your question (and perhaps title) to tell the people about your problem ... –  mliebelt Nov 10 '11 at 8:47
@mliebelt, does the above authorization works for LDAP based authentication as well? I mean, users in the LDAP can access the repos but not able to set read,write permissions for all. I am not able to use "limit" because there are no groups created in LDAP. Please suggest. –  anand Sep 17 '13 at 9:33

Your Answer


