Using SVN post-commit hook to update only files that have been committed

夙愿已清 提交于 2019-11-28 04:44:36

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

For Windows:

for /F "eol=¬ delims=¬" %%A in ('svnlook dirs-changed %1 -r %2') do svn export "file:///c:/path/to/repo/%%A" "c:/svn_exports/%%A"  --force

Just copy the above into your post-commit hook batch file (or window for VisualSVN) and you're done - you'll get the updated directory exported to c:\

You could try using %1 instead of c:/path/to/repo above, but I found that it didn't work because VisualSVN give the %1 path with back-slash path separators, and svnlook gives them with forward-slashes. This doesn't seem to work right so I hard-code the repo path (I got "The filename, directory name, or volume label syntax is incorrect" errors)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!