SVN Hook Fork - Manual

SVN Hook Fork Manual

Installation

To install SVN Hook Fork you will need to be able to edit the subversion hooks. You may also need to be able to change ownership/permissions of files so that the subversion server can write and execute them.

  1. Get subversion and Python installed and working.

  2. Get SVN Hook fork and install the files. We will be using /usr/local/bin for the executable and /etc for the configuration.

    svn checkout http://svn.tepic.co.uk/svn/tools/svn-hook-fork cp svn-hook-fork/svn-hf-post-commit.py /usr/local/bin chmod +x /usr/local/bin/svn-hf-post-commit.py cp svn-hook-fork/demo-post-commit.cfg /etc/svn-hf-myrepo.cfg

  3. Configure the subversion post commit hook to execute SVN Hook Fork

    cd /svn-data-directory/myrepo/hooks cp post-commit.tmpl post-commit vi post-commit

    Change the last line of post-commit to read (without the line break):

    /usr/local/bin/svn-hf-post-commit.py /etc/svn-hf-myrepo.cfg "$REPOS" "$REV"

Configuration

The demo configuration in svn-hook-fork/demo-post-commit.cfg contains example configuration values and documentation. Key configuration values are explained below:

email_???
These values are used to specify how emails should be sent. It is not necessary to specify SMTP-AUTH parameters unless your email server requires them.
log_file
It is recommended that you specify a location for the log file which must be writable by the subversion server. At this time no log rotation is performed.
tmp_dir
The temporary directory must be writable by the subversion server; use this value to override if the normal system default is not.
svnlook
SVN Hook Fork requires that the subversion utility svnlook is available and working. If the default does not work use this value to specify it.

Executable sections

Executable sections are denoted by regular expressions in square brackets - there are several examples in svn-hook-fork/demo-post-commit.cfg.

When a commit takes place each commited file is compared against each regular expressions and, if a match is found, the section executed. The executable code can be in any language executable by the shell, for example Python, Perl or Shell.

Substitutions

Within the executable code all occurances of $REPOS and $REV will be replaced by the repository and revision respectively.

Flow Control Commands

In addition to the executable code the following SVN Hook Fork commands can be used:

!email <address>
This command captures all STDOUT and STDERR and emails it to the given <address>.
!skip <regex>
Skip over sections until the one named <regex>- then continue testing and executing normally. If <regex> matches than that section will be immeadiately executed.
!stop
Stop processing of further sections. Without this other sections with matching regexs may also execute.

Examples

This example sends a notification email whenever a commit occurs.

[.*] #!/bin/sh !email nat@example.com svnlook info $REPOS $REV

This example automatically rolls out changes in the GodWars II documentation to the live site.

[^www.tepic.co.uk/gw2docs/.*] #!/bin/sh cd /www/www.tepic.co.uk/htdocs/gw2docs /www/svn.tepic.co.uk/bin/svn up !email nat@tepic.co.uk !stop

If you have any question please ask me.