SVN configurable pre-commit hook

r688 | coelho | 2011-09-07 11:47:15 +0200 (Wed, 07 Sep 2011)

NAME - configurable pre-commit hook for subversion.

SYNOPSIS [--help, --man or other options] REPOS TXN


This script performs sanity checks about what is being committed. It is designed to be run directly or indirectly as a subversion pre-commit hook script. It is configured from an INI file. The main point of the script is to think again before committing: it can be configured to be forcible based on the log message contents.


--configuration=inifile or -c inifile

Configuration file to use. Default is to use conf/svn-pre-commit.conf if available within the repository, so that the script can be invoked directly as a pre-commit hook by subversion. See -g option below.

--default or -d

Use default configuration. Do not look for any INI file.

--generate-configuration or -g

Generate the current configuration file on standard output. This can be redirected to a file and tailored as needed.

  sh> -g > /path/to/repos/conf/svn-pre-commit.conf
  # then edit configuration file to your taste
--help or -h

This help.

--man or -m

More help.

--set section.parameter=value or -s sec.par=val

Override the default value of a parameter in a section.

--svnlook=/path/to/svnlook or -l /path/to/svnlook

Specify explicitely which svnlook command to use.

--temporary=/path/to/directory or <-t /tmp>

Path to temporary directory to use, if needed. Default is /tmp.

--verbose or -v

Be verbose. Repeat for more.

--version or -V

Show script revision and exit.


The script expects two arguments, which are mandatory but for help, man, version, and configuration generation options.


Directory path to the subversion repository.


Transaction or revision number. The revision number can be used to test the script configuration on prior commits, to check for what would have been done with it.


This script may be invoked:

directly as a hook script

for instance by linking it as pre-commit, in which case the configuration is looked for as conf/svn-pre-commit.conf within the repository, or the default configuration is used.

indirectly from a hook script

in which case the hook script may invoke other checks, and additional options can be passed.

directly from a shell

For testing, for instance to check what would be the result on a previous revision in a given repository e.g.:

  sh> n=12345 ; \
      while let --n ; do \
        echo "### $n" ; \ /path/to/repos $n ; \


The configuration is stored in an INI file. The current configuration can be regenerated with the -g option described above. The output may be redirected to a file and modified to suit your needs. Use this option to see detailed parameters for each section.

The available sections are:


General settings, including whether the commit can be forced with some keyword in the log message, and for each check whether it is activated. Part of the repository can be ignored by the script.


Check for replaced files.


Filter out multi-level svn:mergeinfo properties on a path.


Check allowed characters in file and directory paths.


Filter filenames.


Filter dirnames.


Check for allowed or denied suffixes.


Filter out added empty directories.


Check for svn conflict markers in files.


Check for maximum file size.


Append revision information about this script to generated messages.


Check svn:* file or directory property names.


Check non-svn file or directory property names.


Check property values.


Check svn:* revision property names.


Check non-svn revision property names.


Check revision property values, for instance the log message.



(c) 2009-2011 Fabien Coelho <svn-pre-commit at coelho dot net>

This is free software, both inexpensive and available with sources. The GNU General Public License v3 or more applies (GPLv3+). The brief summary is: You get as much as you paid for, and I am not responsible for anything. See for details.


The latest version of the script is available at


Just put the script in your path, or copy it directly as a pre-commit hook.

The script relies on three perl modules: Config::IniFiles, Getopt::Long, and Pod::Usage. Although the two later modules are pretty standard, the former one may need to be installed via your packaging system or using CPAN. For instance, package libconfig-inifiles-perl is needed on Debian/Ubuntu. See your system administrator.


All softwares have bugs, this is a software, hence...

Maybe the implementation would be more efficient in python, using bindings which access the repository contents directly instead on relying on svnlook.

The script is not nicely extensible, say with some clever object-oriented interface or the like, possibly in python. It is just plain perl. I like that.

Running svnlook pl on revision properties within a transaction does not seem to work with subversion 1.5. There is a partial workaround.

People do not like their commits to be rejected. Really. They usually do not read the error message. Enforcing a commit policy has a weak pedagogical value when a deadline is coming and the urgent work is bounced. You won't get many thanks for deploying such a script.


This documentation is about $Revision: 688 $ of the script.