B/W Rainbow

September 5, 2008


In one of our recent project, we were looking for an automated script that update the working copy of our dev server as soon as someone commit the changes to the SVN.

We were using a Linux server (Fedora) to integrate all the modules developed by almost 15+ developers. I learnt a valuable lesson from the projects in the recent past, it is not so easy to integrate all the modules developed by a team at the end of the project. So I suggested my team that integrating modules while developed would be the best thing (from my exp. anyway ).

Our Dev server running SVN and LAMPP, all we need is an automated script that updates the working copy of our application which resides in htdocs of LAMPP as soon as someone commit their changes, so that they can easily identify the issues as soon as someone commit the conflicts. And also it would be really easy for us to show the demo of the app. at any to the client (i.e., No integration headache at the time of the call).

PHP: the right tool?

As usual I wrote a script in php to run the SVN UPDATE command with PHP exec() function. Oops!! It doesn’t work as expected.


$ret = exec(‘svn update /opt/lampp/htdocs’, $ret2, $ret3);
echo  $ret;


I stumbled Google to know what’s wrong with this code. It returns the following valuable results.

I finally have come to a conclusion that PHP is not the precise tool for the task. So “How did you achieve? Which is the best tool to achieve this?”

I can’t say which one is the best, but this is how I automate the task.

SVN has a feature built-in called hook which is designed specifically to do similar tasks. Don’t know why I’m hearing hooks frequently now-a-days (Drupal uses hooks, Joomla 1.5 uses hooks, hooks! hooks!! hooks!!! )


  • Create a file in C to run the command “svn update“. In my case the file was svn_update.c in /bin.
  • svn_update.c

#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
int main(void) {

execl("/usr/bin/svn", "svn", "update", "/opt/lampp/htdocs/ ", (const char *) NULL);



  • Compile the file with the following command “gcc svn_update.c -o svn_update
  • Create a file called “post-commit” in the hooks directory of your SVN repository:
  • post-commit

# #!/bin/sh

  •          Chmod your post-commit with the following command “chmod 0755 post-commit

That’s all you have to do, now SVN will do the rest. You can download the files, svn_update.c and post-commit here.


Apache SVN @  http://www.sematopia.com/?p=218

Alternate to C @ http://forum.webfaction.com/viewtopic.php?id=964

Mighty C code @ http://forum.webfaction.com/viewtopic.php?pid=216#p216



  1. Thanks so much! I have no experience with C, so the full explanation as well as the compiled code puts it all together for me.

    Comment by Jason — March 31, 2009 @ 2:21 pm | Reply

  2. Hello, I have a problem that I can’t write the Lock-File in /www/myproject/.svn/lock – I try to put the www-Group in the svn-Group and add the svn-User to the www-group and also chown 777 (for development only) all directories. But this can not be the right way. 🙂

    I don’t know under which user the svn_update command uses when I commit a new Version from my computer (Windows/Tortoise SVN). When I look at the server, then the lock file is not present.

    Can you help me?

    Comment by Roland T. — March 31, 2009 @ 10:46 pm | Reply

  3. Why don’t writing your code directly in the post-commit file?
    So it’ll looks like:
    svn update /opt/lampp/htdocs/

    that’s mean no need for C file and compilation, looks so much easier to me.

    Comment by Nyro — June 16, 2009 @ 1:42 pm | Reply

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at WordPress.com.

%d bloggers like this: