Skip to: Site menu | Main content

Check your commits!

SVNChecker is a framework for Subversion pre-commit hook scripts. The SVNChecker handles Subversion (SVN) pre-commit hooks in order to implement checks of files before they are commited. For example, you can check for the code style or unit tests.


SVNChecker Overview

Document Version 1.0

28. September 2007



SVNChecker is a framework for Subversion pre-commit hook scripts. The SVNChecker framework handles Subversion pre-commit hooks in order to implement checks of files before they are commited. For example, you can check for the code style or unit tests. The output of the checks can be send by mail or be written into a file or simply print to the console.


Copyright 2006 Deutsches Zentrum für Luft- und Raumfahrt e.V. (DLR)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.



SVNChecker is written in


Checks are scripts that do a particular check on the transaction, e.g. pylint
or unit tests. They are located in the `checks` folder. All checks have to define
a class `Check` with a main method.

class Check:
    (msg, exitCode) main(transaction, config)


Handlers are scripts that do something with the result of the checks. For example, they send
an email or create console output. They are located in the `handlers` folder. All
handlers have to define a `Handler` class with a main method.

class Handler:
    void main(transaction, config, module, msg, exitCode)

The Transaction class

The transaction class is responsible for getting information about the current
transaction, for example, to be committed files or committing user. It has the
following functions:

String getUserID()
String{} getFiles()
String getFile(filename)
String getCommitMsg()
String getReposPath()
String getRevision()
Boolean fileExists(filename)
String getKeyword(keyword, filename)
Boolean fileExists(filename)
String getKeyword(keyword, filename)

The Configuration class

The configuration class is responsible for getting configuration variables. It
has the following self-explaining functions:

String[] getArray(String)
String getString(String)
Boolean getBoolean(String)
Integer getInteger(String)



Subversion 1.2 is required. Some checks or handlers may depend on external tools or other modules, those have to be installed on the server, otherwise an error will be raised.




To install those scripts you have to create two hook files in your svn hooks
directory (`pre-commit` and `post-commit`). Both have to be executable:

pathtosvnchecker/ PreCommit $1 $2 || exit 1


pathtosvnchecker/ PostCommit $1 $2 || exit 1


Configuration file

The script searchs for the `svncheckerconfig.ini` file in the current hooks
directory. Multiple values can be comma separated. All configuration, which
checks and handlers are enabled and the configuration of the particular
checks and handlers, has to be done in this file. If no configuration file was
found, an error will be raised.

File format

The configuration file has a standard ini file format, e.g.


For the available configuration variables please read the documentation of the
particular module.

Checks and Handlers

For each check you have to specify which Handler will be executed on Success and
on Failure, for example, if you have the Log check:


After that you have to configure the particular variables of the checks, e.g.
mail addresses or files, they are explained later.

Resolving of Variables

The resolving of variables is done in two steps. First, it will be looked for the exact variable name, e.g. "Checkstyle.!SuccessFile". If this one could not be found, the value before the "." will be replaced by Main, e.g. "Main.!SuccessFile".


You can split the configuration file into profiles, e.g. you could specify one
profile per project. All profile variables have to be in a section named with
the profile name. For each profile you have to specify a regular exression.
The default section is "Default" and does not have a Regex variable.
If the path of the commited file relative to the repository location matches
this profile, it is used and no other profile will be checked. If no matching
profile was found the default profile with no prefix is used. If a particular
variable was not found in the profile the default variable will be used.
If this variable does not exist an error will be raised. A small example,
assuming that your profile name is TENT:


The `Checks.PreCommit` variable has been overwritten, but the `Checks.PostCommit`
variable is not specified, thus the global one from the example above will be used.


You always have to replace `%Check%` in the config file with the real name of the check, without `.py` extension.

Main Functions of the framework.


Writes the messages into a file.


Sends the messages per mail.


Prints the messages to the console.


Adds the log message to the correct MANTIS issue and updates the SVNRevision field of the bug.


Handles access to the MANTIS issue tracker via the
Mantis Connect Web Service.


Creates the logfile.


Checks if a log message contains a valid MANTIS ID, with a MANTIS ID <#> that is set to status 'in_progress' and if the MANTIS ID belongs to the commmiter.


Checks java files for code style.

Requirement: checkstyle


Checks if svn:keywords for added files are set.


Checks if a unit test for a file is commited.


Checks xml files for correctness and agains schema and dtd.

Requirement: xerces-2.8


Implements simple access rights. A list of rule names is given. Then for each rule a list of files to check and ignore is given and if you are not in the !AllowUsers group or are in the !DenyUsers group you dont' have rights to edit them.


Checks python files against pylint.