一、本机上操作

1、当/data/server/ 目录下有新文件提交时,自动更新。

cd ../hooks

cp post-commit.tmpl post-commit

vim post-commit

#!/bin/bash

REPOS="$1"                           

REV="$2"                             

DIR=/data/server                        

export LC_ALL=en_US.UTF-8

export LANG=en_US.UTF-8

export LANGUAGE=en_US.UTF-8      

svn update $DIR --username xxxxxxx --password xxxxxxx --no-auth-cache

echo `date`,`whoami`,$REPOS,$REV >> /tmp/svn_update.log


chmod +x post-commit

二、更新到远程服务上

1、在远程服务器上checkout所要目录(/data/server/check)

mkdir /data/server;cd /data/server

svn checkout svn://.../check


在该机器上创建脚本

vim /root/svnup.sh

#!/bin/bash  

/usr/bin/svn update /data/server/check

chmod +x svnup.sh


2、在svn服务器上创建hooks(没有免密码登陆的情况下)

cd ../hooks

cp post-commit.tmpl post-commit

vim post-commit

#!/usr/bin/expect

set host "192.168.224.30"

set port "1101"

set username "root"

set password "12345678"

set action "/bin/bash /root/svnup.sh"

spawn ssh -l ${username} ${host} -p ${port} ${action}

expect {

"(yes/no)?" { send "yes\r"; exp_continue}

"password:" { send "$password\r" }

}

expect eof


在svn update时不更新某些目录

svn update --set-depth=exclude dir1 dir 2

在用上述方法规避一些目录后,想把规避的目录再次update出来

svn update --set-depth infinity dir1 dir2



PS:使代码的时间戳和版本库上提交代码的时间戳保持一致

vim ~/.subversion/config 
use-commit-times=yes