Click here to Skip to main content
13,559,559 members
Click here to Skip to main content
Add your own
alternative version


31 bookmarked
Posted 31 Dec 2006
Licenced CPOL

SvnPerms dot Net

, 9 Sep 2008
Rate this:
Please Sign up or sign in to vote.
C# port of pre-commit script.

Sample Image - SvnPermsNet.jpg

Sample Image - SvnPermsNet.jpg


I implemented Subversion on windows to use Active Directory Authentication. I could not get the hook script to function correctly, however, and I've been looking for an excuse to try out .NET Framework 2.0. So here it is: is a C# port of the hook script supplied with Subversion. The only feature I've added is log message validation. This article assumes that you are familliar with SVN.

Check out a working copy using TortoiseSVN.

System requirements

  1. SVN command line client
  2. .NET Framework 2.0

The components

  1. svnperms.xml
  2. SvnPerms.exe
  3. pre-commit.bat


The configuration file:


        <setting name="SvnDir">C:\svn\bin</setting>
        <setting name="LogRegex">[a-zA-Z0-9]</setting>
        <setting name="LogRegexMsg">You failed to supply a valid log message.</setting>
        <setting name="ErrMsgSuffix">Please contact your SVN admin.</setting>


        <default repos="repo1,repo2">
            <location path

                =&quot;^\btrunk\b\/.*" actions

            <location path

                =&quot;^\btags\b\/\w+\/" actions

            <location path

                =&quot;^\bbranches\b\/\w+\/" actions


            <location path

                =".*" actions

            <location path=".*" actions="add,remove,update">*</location>

  1. The setting[@name='SvnDir'] element: the path to the SVN command line client.
  2. The setting[@name='LogRegex'] element: regex to validate log messages.
  3. The groups element: groups of users.
  4. The sections element: repos to match.
    • The default section allows for repos that all have the same structure, e.g. trunk, branches and tags.
    • Repos with other structures can be defined with more sections.
    The sections consist of location elements -- each with a change path regex attribute -- and an actions attribute containing "add," "remove" and "update" or any combination of the three. The text of the location element contains a comma-separated list of groups and users.


Calling SvnPerms.exe with no arguments:

USAGE: SvnPerms TXN|REV REPOS [ CONF ] [ -r ]
      TXN     Query transaction TXN for commit information.
      REPOS   Use repository at REPOS to check transactions.
      CONF    Config file path;
              defaults to 'svnperms.xml' in application directory.

      -r      Debug mode:
              Uses revision number instead of commit transaction nubmer.
Author: Riaan Lehmkuhl 2006.

Calling the SVN commands:

private static string SvnCmd(string cmd) {
    string fileName = string.Empty;
    string arguments = string.Empty;

    // build Svn command.

    switch (cmd.ToLower()) {
        case "changed" :
        case "author" :
        case "log" :
            fileName = string.Concat(_svnDir, "svnlook");
            arguments = string.Concat(" ", cmd, " ", _switch,
                " \"", _txnRev, "\" \"", _repos, "\"");
        default :
            _stdOut = null;
            _stdErr = "Svn Command '" + cmd + "' not supported.";
            return _stdOut;

    // call svn command.

    System.Diagnostics.Process process
        = new System.Diagnostics.Process();
    process.StartInfo.FileName = fileName;
    process.StartInfo.Arguments = arguments;
    process.StartInfo.UseShellExecute = false;
    process.StartInfo.RedirectStandardOutput = true;
    process.StartInfo.RedirectStandardError = true;
    process.StartInfo.CreateNoWindow = true;

    // read the output.

    _stdErr = process.StandardError.ReadToEnd();
    _stdOut = process.StandardOutput.ReadToEnd();

    return _stdOut;

I've tried to comment the code as much as I had time for, to explain how the application fits together. When the log has been validated sucessfuly and the user has the required permissions, SvnPerms.exe will exit with an exit code of 0. Otherwise, it will exit with a non-zero exit code that will cancel and rollback the commit.



[drive]:\[path]\SvnPerms.exe %REV% %REPOS%

Modify the path to where you have put SvnPerms.exe. Copy the pre-commit.bat file to the repository's "hooks" directory. Any commits will be validated by SvnPerms.exe.


16 August 2008
  • Upgraded Solution to VS 2008.
  • Log error message can be configured from config.
  • Error messages can suffixed by a custom message from config.
  • Some minor bug fixes.

16 May 2007

  • Updated usage message.
  • Fixed bug in argument handling.
  • Ignore empty changes.
  • Added support for multiple permissions on a repository.

31 Dec 2006

  • Original article posted


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Riaan Lehmkuhl
Software Developer adhdForge
South Africa South Africa
Me, a disorder of the brain that results in a disruption in a person's thinking, mood, and ability to relate to others.

You may also be interested in...

Comments and Discussions

QuestionParameters to be passed to pre-commit.bat file Pin
Member 945518625-Sep-12 6:17
memberMember 945518625-Sep-12 6:17 
AnswerRe: Parameters to be passed to pre-commit.bat file Pin
Riaan Lehmkuhl14-Jul-13 20:43
memberRiaan Lehmkuhl14-Jul-13 20:43 
GeneralPermission question - Subversion & Apache Pin
mahkomat10-Sep-08 1:38
membermahkomat10-Sep-08 1:38 
GeneralSmall things Pin
marcusmaday27-Aug-07 12:03
membermarcusmaday27-Aug-07 12:03 
QuestionNot working Pin
Petar Srdanovic31-Jul-07 4:26
memberPetar Srdanovic31-Jul-07 4:26 
AnswerRe: Not working Pin
Petar Srdanovic31-Jul-07 4:37
memberPetar Srdanovic31-Jul-07 4:37 
GeneralRe: Not working Pin
Riaan Lehmkuhl31-Jul-07 5:05
memberRiaan Lehmkuhl31-Jul-07 5:05 
AnswerRe: Not working Pin
Riaan Lehmkuhl31-Jul-07 5:04
memberRiaan Lehmkuhl31-Jul-07 5:04 
GeneralError test Pin
amarwane4-May-07 10:01
memberamarwane4-May-07 10:01 
GeneralRe: Error test [modified] Pin
Riaan Lehmkuhl13-May-07 23:31
memberRiaan Lehmkuhl13-May-07 23:31 
AnswerRe: Error test Pin
Riaan Lehmkuhl15-May-07 23:34
memberRiaan Lehmkuhl15-May-07 23:34 
NewsFuture updates Pin
Riaan Lehmkuhl2-Jan-07 17:17
memberRiaan Lehmkuhl2-Jan-07 17:17 
Generalexcellent Pin
Ertan Tike2-Jan-07 12:59
memberErtan Tike2-Jan-07 12:59 
GeneralRe: excellent Pin
Riaan Lehmkuhl2-Jan-07 17:21
memberRiaan Lehmkuhl2-Jan-07 17:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03-2016 | 2.8.180527.1 | Last Updated 9 Sep 2008
Article Copyright 2006 by Riaan Lehmkuhl
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid