SVN configurable pre-commit hook

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


NAME

svn-pre-commit.pl - configurable pre-commit hook for subversion.


SYNOPSIS

svn-pre-commit.pl [--help, --man or other options] REPOS TXN


DESCRIPTION

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.


OPTIONS

--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> svn-pre-commit.pl -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.


ARGUMENTS

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

REPOS

Directory path to the subversion repository.

TXN

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.


INVOCATION

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" ; \
        svn-pre-commit.pl /path/to/repos $n ; \
      done


CONFIGURATION

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

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.

replace

Check for replaced files.

mergeinfo

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

path

Check allowed characters in file and directory paths.

filename

Filter filenames.

dirname

Filter dirnames.

suffix

Check for allowed or denied suffixes.

emptydir

Filter out added empty directories.

conflict

Check for svn conflict markers in files.

filesize

Check for maximum file size.

showinfo

Append revision information about this script to generated messages.

svnprops

Check svn:* file or directory property names.

otherprops

Check non-svn file or directory property names.

propvalues

Check property values.

svnrevprops

Check svn:* revision property names.

otherrevprops

Check non-svn revision property names.

revpropvalues

Check revision property values, for instance the log message.


LICENSE

GNU GPLv3

(c) 2009-2011 Fabien Coelho <svn-pre-commit at coelho dot net> http://www.coelho.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 http://www.gnu.org/copyleft/gpl.html for details.


DOWNLOAD

The latest version of the script is available at http://www.coelho.net/svn-pre-commit.pl.


INSTALLATION

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.


BUGS

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.


VERSION

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