SVN and Auto Checkout after Commit

VersionControl is a great thing. But if you work as a web developer you got one problem. Often its better to view a web page in the production environment. And in the most cases its a grate think to have the current development revision online in a production like testing environment, so you can show people the current work.

When I started to use subversion, I wanted to have an automatic way to check out the repository to the webroot. And there is a nice way to do this:

The SVN repository has hooks to do work after special events.

If you list your SVN directory you can find a folder called ‘hooks’. This folder contains some "callback" script for all SVN actions.

total 36
-rwxrwx--- 1 root subversion 2769 Aug 3 17:29 post-commit
-rwxrwx--- 1 root subversion 1690 May 29 21:54 post-lock.tmpl
-rwxrwx--- 1 root subversion 2307 May 29 21:54 post-revprop-change.tmpl
-rwxrwx--- 1 root subversion 1606 May 29 21:54 post-unlock.tmpl
-rwxrwx--- 1 root subversion 2982 May 29 21:54 pre-commit.tmpl
-rwxrwx--- 1 root subversion 2038 May 29 21:54 pre-lock.tmpl
-rwxrwx--- 1 root subversion 2764 May 29 21:54 pre-revprop-change.tmpl
-rwxrwx--- 1 root subversion 1980 May 29 21:54 pre-unlock.tmpl
-rwxrwx--- 1 root subversion 2758 May 29 21:54 start-commit.tmpl

The script post-commit is executed by the user of the subversion server after every commit action with the params:
"$REPOS" "$REV"

now you can add your fancy commands to the post-commit script.

for a simple checkout it is as simple as:
/usr/bin/svn update /var/www --username username --password password

I think the best solution to handle the rights is sudo. Of course you dont want the subversion user to have access to your webroot.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.