Recently I had to set up a subversion hook, and found the documentation a bit lacking. So, here is a guide, that will hopefully help someone.
What: I have a subversion repository for a website, which I would like to be able to test. So upon a commit to the repository, a website on the same server should be updated as well. The official FAQ pointed me in the right direction – using a post-commit hook, however many details were left out.
How: I assume your repository is already set up at /path/to/rep, and your web site is located at path/to/web. What we first need to do, is checkout the contents of repository into the website, by running the following:
svn checkout http://localhost/project/branch /path/to/web
At this point it is a good idea to modify config files with information such as DB access info, and other installation specific settings, which shouldn’t be overwritten in the future.
Now for the tricky part. To make the site update upon every commit you need to set up a post-commit hook. You will find a template for such a hook in /path/tp/rep/hooks/post-commit.tmpl Open the file and replace whatever command is at the bottom with the following:
/usr/bin/svn update /path/to/web
This line will execute every time something is committed to the repository. Make sure to have the correct path to svn! Rename post-commit.tmpl to post-commit, and you’re ready to go!
Problems: This might not be enough, depending on the way your server is set up. If subversion doesn’t have write access to apache files, you will need to set up an external batch file, as described in the FAQ. There may be other problems utilizing the hook, in which case you should check this and follow the steps to get your hook working. This was not enough for me.
The problem I ran into, is that the hook did not seem to execute. It ran fine from a command line, but nothing was done automatically. There was no log file to point me to the issue either.
To debug the issue I renamed the original hook into post-commit-run, and modified the original one to do the following (using this as a tip):
exec $1/hooks/post-commit-run %* > $1/hooks/post-commit.log 2>&1
This will direct all output during hook execution to the log file. Making sure I set the correct permissions to the hooks and the log file, I did a commit. The log entry then led me to authentication problems, which were easily solved.
This will work on a *nix server, but the procedure should be very similar in a Windows environment. There are plenty of resources on the net about that.