I am using an SVN repository for my web development work. I have a development site set up which holds a checkout of the repository.
I have set up an SVN post-commit hook so that whenever a commit is made to the repository the development site is updated:
cd /home/www/dev_ssl
/usr/bin/svn up
This works fine but due to the size of the repository the updates take a long time (approx. 3 minutes) which is rather frustrating when making regular commits. What I'd like is to change the post-commit hook to only update those files/directories that have been committed but I don't know how to go about doing this. Updating the "lowest common directory" would probably be the best solution, e.g.
If committing the follow files:
It would update the directory: /branches/feature_x/
Can anyone help me create a solution that achieves this?
Update:
You might use svnlook dirs-changed
and svn up -N
to update only the contents of each folder changed:
cd /home/www/dev_ssl
svnlook dirs-changed [REPOS] -r [REV] | xargs /usr/bin/svn up -N
Or, if per-file might be better for you (using sed
to strip action characters):
svnlook changed [REPOS] -r [REV] | sed "s/^....//" | xargs /usr/bin/svn up
#!/bin/bash
REPOS="$1"
REV="$2"
# A - Item added to repository
# D - Item deleted from repository
# U - File contents changed
# _U - Properties of item changed; note the leading underscore
# UU - File contents and properties changed
# Files and directories can be distinguished, as directory paths are displayed with a trailing "/" character.
LOOK=/usr/local/svn/bin/svnlook
SVN=/usr/local/svn/bin/svn
DEV=/var/www/test
cd /var/tmp/svn
for changes in `$LOOK changed $REPOS | awk '{print $1 "=" $2;}'`;
do
len=${#changes}
idx=`expr index "$changes" =`;
directory=${changes:$idx};
action=${changes:0:$idx-1};
if [ ${changes:len-1} = '/' ]
then
case "$action" in
"A" ) \
mkdir --mode=775 -p $DEV/$directory;
chown nobody:nobody $DEV/$directory;
chmod 775 $DEV/$directory;
;;
"D" ) \
rmdir $DEV/$directory;
;;
esac
else
case "$action" in
"A"|"U"|"UU" ) \
$SVN export --force --non-interactive -r HEAD -q file://$REPOS/$directory;
BASE=`basename $directory`;
DIR=`dirname $directory`;
chown nobody:nobody $BASE;
chmod 775 $BASE;
mkdir --mode=775 -p $DEV/$DIR;
cp -f --preserve=ownership $BASE $DEV/$DIR;
unlink $BASE;
;;
"D" ) \
rm -f $DEV/$directory;
;;
esac
fi
done
exit 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With