Skip to content

Instantly share code, notes, and snippets.

@jasdeepkhalsa
Last active September 13, 2022 17:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasdeepkhalsa/4570210 to your computer and use it in GitHub Desktop.
Save jasdeepkhalsa/4570210 to your computer and use it in GitHub Desktop.
Post-Commit Shell Script for Subversion (SVN) for updating only changed files
#!/bin/bash
# Before using please rename from post-commit.sh to post-commit
# Add this file to the hooks directory in the svn root folder
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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment