1

I used some script i found somewhere:(im a total svn noob, is it used for copying files after committing them to a repo?)

#!/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/bin/svnlook
SVN=/usr/bin/svn 
DEV=/usr/local/node/

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

Paths:

Path i want to copy all the modified files after committing:
/usr/local/node/

Repo location:
/var/lib/svn/api/

Hook location:
/var/lib/svn/api/hooks/post-commit

When i run it from terminal i get:

Repository argument required Type 'svnlook help' for usage.

When i do a commit /usr/local/node/ isn't changed

Writecoder
  • 613
  • 2
  • 8
  • 27

1 Answers1

1

I assume you forgot to pass this script any arguments when you ran it by hand. The first argument ($1) is assigned to $REPOS, which is used in the svnlook command executed in the for loop.

Be sure to run the script correctly -- with the repository path as the first argument and the revision just committed as the second argument.

Be sure to spend some time with the SVN book before executing this -- it must be run as root (see the chown(1) command) and it might remove data you care about (see the unlink(1) and rm(1) commands).

sarnold
  • 102,305
  • 22
  • 181
  • 238
  • Is there any script around just simple copying the repo after commit to /usr/local/node/ ? I don't care if also not modified files are moved because i'm working on only a couple of files(for now). Thanks for the comment & warning! – Writecoder Nov 22 '11 at 00:58
  • I prefer to have manual control over exporting changes to somewhere else, so I'd recommend running [`svn export`](http://svnbook.red-bean.com/en/1.0/re10.html) by hand (maybe from a `Makefile` recipe) whenever you want to deploy something new. That script you found sure looks like it ought to do something similar, but I'd be careful to test its behavior a few times to make sure it works as you expect. – sarnold Nov 22 '11 at 01:02
  • Did something wrong, instead of "chmod +x post-commit" at the beginning i did something out of my memory like "chmod -x". Anyways everything is working using svn export, i wanna lick your face. – Writecoder Nov 22 '11 at 01:53