Wednesday, October 28, 2009

SVN Hooks

I am working on a project where I need directory of my cakePHP application on the server update on each svn commit. Why? Because I am lazy. I don't want to login to remote server every time I commit something, run svn update...or worse ftp. So I've been reading about svn hooks, and it's a very powerful thing.

These are the steps to make it work:



  • Create and compile c program that will perform svn update, and save it somewhere let's say in /svn/autoupdate

    1. #include <stddef.h>  
    2. #include <stdlib.h>  
    3. #include <unistd.h>  
    4. int main(void)  
    5. {  
    6. execl("/usr/local/bin/svn""svn""update",  
    7. "${dirNameToUpdate}",  
    8.       (const char *) NULL);  
    9. return(EXIT_FAILURE);  
    10. }  
    11. </unistd.h></stdlib.h></stddef.h>  



  • Add post-commit to svnrepo/hooks where compiled c program is referenced:
    1. #!/bin/sh  
    2. /svn/autoupdate/autoupdate  


  • chmod +x post-commit


Try to commit something to svn on remote server and watch svn hooks magic in action.

Blogger Syntax Highliter