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

前端 未结 4 1165
有刺的猬
有刺的猬 2020-12-08 02:49

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-commi

相关标签:
4条回答
  • 2020-12-08 03:29

    Have a look to this home made script : http://envrac.blogdns.net/shellscripts/export-automatique-d-un-projet-subversio !

    0 讨论(0)
  • 2020-12-08 03:31

    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
    
    0 讨论(0)
  • 2020-12-08 03:36

    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)

    0 讨论(0)
  • 2020-12-08 03:46
    #!/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
    
    0 讨论(0)
提交回复
热议问题