views:

189

answers:

2

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?

+2  A: 

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.

Valentin Rocher
I'm unsure on how to modify the post-commit hook script to do what you suggest. As far as I am aware the script is just a type of batch file. It just contains commands that I want to execute. How can I use logic and what language would I use?
Camsoft
I'll modify my answer to precise these details.
Valentin Rocher
Since it's a batch file you have access to the underlying batch language features. So it's just like writing a .bat (for windows) or a .sh (for unix)The thing to remember is that the environment in which a post commit hook is executed is pretty bare. You may need to setup some variable especially PATHOnce that's setup you can use the OS normal features for batch files that includes conditionnals, loops and stuff.
Jean
-1: since the path to the repository will not contain trunk... it will always be the path the repository root. You need to use the information to query the repo to get the list of files that were in that revision. I will remove the downvote when the answer is updated.
Paul Wagland
changed the answer, thanks for the comment
Valentin Rocher
Cool, I have removed the downvote.
Paul Wagland
+2  A: 

In addition to the answer from Bishiboosh, it is worth noting that the hooks can be any program. That is, if you wanted to, you could write the program in C. The parameters that are passed are described in the doc.

For a good repository of scripts to get inspiration from, have a look at the subversion tools page. In general, if you want to do some conditional processing based on the contents of the transaction, and you do, since you only want to process if the files are in trunk, then it will be easiest to use Python, since that comes with a bunch of tools to examine the transactions. This script is a good place to start looking for inspiration.

Note, that the path to the parameter, is not the same as the path to the file that you are checking in. You could have multiple files in the checkin after all… What you are passed is the location of the repository, and the revision of the change. Using these two pieces of information you can get the information about the change from the repository, and use that information to decide whether to perform an action or not in the post-commit hook.

Here is another example (in Perl) That explicitly checks the path of the files in the checkin. This is a much more complicated script, but most likely the salient parts can be ripped out and re-used.

Paul Wagland
do you mind if I add information from your answer in mine ? I already plussed yours, but having all answers in one question can help others to understand more easily ?
Valentin Rocher
Bishiboosh... please do!
Paul Wagland
That's helpful. Better start learning Python. Do you know any good tutorials for Python?
Camsoft
@Camsoft: <http://stackoverflow.com/questions/70577/best-online-resource-to-learn-python> or <http://stackoverflow.com/questions/207701/python-tutorial-for-total-beginners> are good places to start ;-) I have also updated the answer with a Perl script, that might be more helpful if you already know Perl…
Paul Wagland
Thanks! The Perl example is better. I'm a Web Developer so I know JavaScript and PHP so the Perl syntax seems more familiar.
Camsoft