MikoAndras.hu/en

Personal pages for Andras MIKO

Automatic hook creation in every new svn repository

Step for setup

We will need three ingredients for the successful setup:

  • our post-commit script template
  • a script, which will copy our template into the hooks directory
  • and the setup of incron

Post-commit template

Important is to place it somewhere we can find it later, and the copy script can access it.
/home/subversion/templates:

kms@localhost:/home/subversion/templates$ ls -l
total 4
-rw-r--r-- 1 root root 36 Sep 16 22:15 post-commit

For the contents you can read Daniel’s post on Bonetree blog.

Copy script

It checks the parameters given by incron, and if valid, it copies our template to the hooks directory. For better understanding I have dropped some possible validations, and it is not the best solution either.

#!/bin/bash
 
# from where to copy skeleton
PATH_TO_SKELETON=/home/subversion/templates/post-commit
 
# $1 is the filename given from incrond
# $2 is the directory name
PATH_TO_HOOKS_DIR=${1}/hooks
 
PATH_TO_NEW_FILE=${PATH_TO_HOOKS_DIR}/post-commit
 
#retry wait in seconds
TIMEOUT_ON_RETRY=5
 
copy_hook () {
        cp ${PATH_TO_SKELETON} ${PATH_TO_NEW_FILE}
        chmod ugo+x ${PATH_TO_NEW_FILE}
}
 
if [ -d ${PATH_TO_HOOKS_DIR} ]; then
        copy_hook;
else
        sleep ${TIMEOUT_ON_RETRY};
        copy_hook;
fi

incron setup

In fact it has a very similar interface used by cron. For those who’d like to dive into the chaotic sea of configuration possibilities, I highly recommend the detailed description. What you should never forget is to allow access for yourself in the /etc/incron.allow file.

/home/subversion/repository IN_CREATE /usr/local/bin/add_hook.sh $@/$#

This example shows the directory and event under surveillance. IN_CREATE will occur, when we add a new directory or file in the given place. the next item is the script to be run, and the parameters to be given to it. For us it is the new directory’s name.

Directory structure for a new repo before the use of the incron technic (listing on hooks):

kms@localhost:/home/subversion/repository$ ls -la repo_pre_incron/hooks/
total 44
drwxrwxr-x 2 kms kms 4096 Sep 16 11:34 .
drwxrwxr-x 6 kms kms 4096 Sep 16 11:34 ..
-rw-rw-r-- 1 kms kms 2000 Sep 16 11:34 post-commit.tmpl
-rw-rw-r-- 1 kms kms 1690 Sep 16 11:34 post-lock.tmpl
-rw-rw-r-- 1 kms kms 2307 Sep 16 11:34 post-revprop-change.tmpl
-rw-rw-r-- 1 kms kms 1606 Sep 16 11:34 post-unlock.tmpl
-rw-rw-r-- 1 kms kms 2982 Sep 16 11:34 pre-commit.tmpl
-rw-rw-r-- 1 kms kms 2038 Sep 16 11:34 pre-lock.tmpl
-rw-rw-r-- 1 kms kms 2764 Sep 16 11:34 pre-revprop-change.tmpl
-rw-rw-r-- 1 kms kms 1980 Sep 16 11:34 pre-unlock.tmpl
-rw-rw-r-- 1 kms kms 2758 Sep 16 11:34 start-commit.tmpl

and after the successful setup of incron:

kms@localhost:/home/subversion/repository$ ls -la repo_with_incron/hooks/
total 48
drwxrwxr-x 2 kms kms 4096 Sep 16 11:34 .
drwxrwxr-x 6 kms kms 4096 Sep 16 11:34 ..
-rwxr-xr-x 1 kms kms   36 Sep 16 11:34 post-commit
-rw-rw-r-- 1 kms kms 2000 Sep 16 11:34 post-commit.tmpl
-rw-rw-r-- 1 kms kms 1690 Sep 16 11:34 post-lock.tmpl
-rw-rw-r-- 1 kms kms 2307 Sep 16 11:34 post-revprop-change.tmpl
-rw-rw-r-- 1 kms kms 1606 Sep 16 11:34 post-unlock.tmpl
-rw-rw-r-- 1 kms kms 2982 Sep 16 11:34 pre-commit.tmpl
-rw-rw-r-- 1 kms kms 2038 Sep 16 11:34 pre-lock.tmpl
-rw-rw-r-- 1 kms kms 2764 Sep 16 11:34 pre-revprop-change.tmpl
-rw-rw-r-- 1 kms kms 1980 Sep 16 11:34 pre-unlock.tmpl
-rw-rw-r-- 1 kms kms 2758 Sep 16 11:34 start-commit.tmpl

Happy tweaking!

Pages: 1 2

, , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>