Goal

Automatically copy files that are added or modified in a specific folder of an svn repository.
Useful for Web sites, …

Prepare a post-commit script

cd /svn/robots/hooks
cp post-commit.tmpl post-commit
chmod ug+x post-commit

Be careful of the owner/group of this post-commit file because it is the unix user that is dedicated to execute post-commits that must have executable rights.

The post-commit script

Example of script that checks if files in “PhaROS/Scripts” are involved in the latest commit.
If yes, copy them in /var/www.

#!/bin/sh

REPOS="$1"
REV="$2"

for scriptfile in `svnlook changed /svn/robots | awk -F "PhaROS/Scripts/" '{print $2}' | xargs`; do
        svn export --force --non-interactive -q  file:///svn/robots/PhaROS/Scripts/$scriptfile /var/www/Scripts/$scriptfile
done

Test the script

./post-commit /svn/robots 395

Be careful of the rights here too.
This post-commit script may be executed by a different user than yours when testing like above.
The real test is to modify the files in a repository copy and effectively do a commit.

Leave a reply

required

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>