Nov 27 2008

I had a handy mechanism working on my old old CVS server, and I’ve been using it for some time on my current SVN server.

Basically, whenever you commit a file to the repository, if you have a checked out workspace on the same server, then it will automatically update to the latest revision of the checked out branch or trunk. It’s handy so you don’t have to “svn up” every time you make a change, especially if you’re making lots of tiny changes.

This guide was original from Marc Grabanski’s blog, so 99% of credit goes to him.

cd /svnroot/hooks/
cp post-commit.tmpl post-commit
chmod +x post-commit

You can make a little program to update all your SVN repositories, so nano svnupdate.c:

#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
 
int main(void)
{
  execl(
    "/usr/bin/svn",
    "svn",
    "update",
    "/path/to/mywebsite1.co.uk/www/",
    "/path/to/mywebsite2.co.uk/www/",
    "/path/to/mywebsite3.co.uk/www/",
    (const char *) NULL);
  return(EXIT_FAILURE);
}

You can add as many paths as you like there, just copy and paste the line and edit the path to your needs. You need to then compile it, test it.

gcc -o svnupdate svnupdate.c
env - ./svnupdate

Nano your post-commit file and add in the FULL path to your svnupdate program:

/path/to/svnroot/hooks/svnupdate

Leave a Reply