It seems these days I spend more time figuring out annoying problems rather than doing any real work. The following gave me another big headache: Getting SVN to auto-update properly via it’s hooks. SVN provides you the ability to specify hooks after certain events occur with the repository in question. For example, say you have a live application under version control and you want SVN to auto-update the live copy (on the server) after every commit. I guess that makes sense, especially if you want to develop and test in your production environment, on the fly.
In the directory were your repository exists there should be a hooks directory. This directory includes a bunch of tmpl files that get called depending on the event that just occurred. The file that I cared about was the post-commit.tmpl file.
Assuming your running SVN using Apache, then most likely when your post-commit script gets called it will be executed using the user www-data. This is important because it means your repository needs to be checked out via the same user to ensure no permission problems occur. Assuming that OK, then add the following line to your post-commit.tmpl file:
Code:
/usr/bin/svn update <path to repo> --username xxxxxx --password xxxxxx
Hardcoding your SVN password in the file is probably not the best idea, but if your the only one who would have access to the file, then who cares. Notice how I put a full path to SVN, that’s because when the hook scripts get called all environment variables, etc. get removed. The next step, and probably most important, rename the file removing the .tmpl extension and change the ownership so the file becomes executable.
Code:
cp post-commit.tmpl post-commit
chmod +x post-commit
That should do it, so when you update your repository, SVN should auto-update your live working copy. Most likely you’ll run into problems, if so check the links below for more info.
Helpful Link #1
Helpful Link #2
Helpful Link #3