Skip to content
Advertisement

How can I have a post-commit hook that is only called when commits are made to TRUNK?

I have a repository that has the following directories:

  • branches
  • tags
  • trunk

The trunk directory contains the main line of development. I have created a post-commit hook script for the repository that updates a working copy (of trunk) when a user commits back to repository.

It looks something like this:

/usr/bin/svn update /path/to/a/working/copy

I’ve just created a branch of the code as I’m about to start some major changes but noticed that when I commit my changes to branch it calls the post-commit hook and updates the working copy (copy of trunk).

Is there a way I can modify either my post-commit hook script or a setting that I can make that would only update the working copy if the commit was made to the trunk directory and not any other directory?

Advertisement

Answer

As you can see in this documentation, parameters are passed to the post-commit script.

The repository passes two arguments to this program: the path to the repository, and the new revision number that was created.

The post-commit hook could be any program of any type : a bash script, a C program, a python script…What happens is that the shell launches this program, with the two parameters.

You can find a list of interesting scripts here. A good beginning would be this python script, which uses the python svn libs.

Please note that the path provided is not the same as the path to the file that you are checking in (see Paul’s answer). But using this information with the revnum should help you to get the list of the changes, from which you can determine if operations have been done on trunk or not.

Advertisement