简单的svn post-commit-hook用更改的文件更新dir

时间:2011-11-22 00:45:25

标签: linux svn post-commit post-commit-hook

我使用了一些我在某处发现的脚本:(即使是一个总的svn noob,是否用于在将文件提交到回购后复制文件?)

#!/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

路径:

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

当我从终端运行时,我得到:

  

需要存储库参数输入'svnlook help'以供使用。

当我提交/ usr / local / node /时没有更改

1 个答案:

答案 0 :(得分:1)

我假设您在手动运行时忘记了传递此脚本的任何参数。第一个参数($1)分配给$REPOS,在svnlook循环中执行的for命令中使用。{/ p>

确保正确运行脚本 - 将存储库路径作为第一个参数,将修订版本作为第二个参数提交。

确保在执行此操作前花费一些时间与SVN book一起 - 它必须以root身份运行(请参阅chown(1)命令),它可能会删除您关心的数据(请参阅{{ 1}}和unlink(1)命令)。