svnadmin create REPO
每個版本庫的目錄下有一個hooks目錄:
root@SVN:/home/svn/repo# ls /home/svn/repo/
conf dav db format hooks locks README.txt
在每個版本庫下有hooks文件夾,裏面有很多鉤子程序:
root@SVN:/home/svn/repo# ls -l hooks/
total 40
-rwxr-xr-x 1 www-data www-data 332 2010-05-30 16:47 post-commit
-rw-r--r-- 1 www-data www-data 2000 2010-05-30 15:22 post-commit.tmpl
-rw-r--r-- 1 www-data www-data 1663 2010-05-29 23:28 post-lock.tmpl
-rw-r--r-- 1 www-data www-data 2322 2010-05-29 23:28 post-revprop-change.tmpl
-rw-r--r-- 1 www-data www-data 1592 2010-05-29 23:28 post-unlock.tmpl
-rw-r--r-- 1 www-data www-data 3488 2010-05-29 23:28 pre-commit.tmpl
-rw-r--r-- 1 www-data www-data 2410 2010-05-29 23:28 pre-lock.tmpl
-rw-r--r-- 1 www-data www-data 2796 2010-05-29 23:28 pre-revprop-change.tmpl
-rw-r--r-- 1 www-data www-data 2100 2010-05-29 23:28 pre-unlock.tmpl
-rw-r--r-- 1 www-data www-data 2830 2010-05-29 23:28 start-commit.tmpl
在執行commit操作之後會自動執行post-commit這個鉤子程序。
因此可以設置post-commit來自動更新:
操作步驟如下:
1. 使用checkout建立一個工作複本
mkdir /home/web
root@SVN:/home# chown www-data:www-data web
ls -l web
drwxr-xr-x 2 www-data www-data 4096 2010-05-30 16:15 web
必須使用apache的所屬用戶和組(在ubuntu下面的是www-data)來執行:check out
root@SVN:/home/web# sudo su www-data
$ cd /home/web
$ svn checkout http://svn.love.com/svn/repo/www/
Authentication realm: <http://svn.love.com:80> Repo Auth
Password for 'www-data':
Authentication realm: <http://svn.love.com:80> Repo Auth
Username: jack
Password for 'jack':
-----------------------------------------------------------------------
ATTENTION! Your password for authentication realm:
<http://svn.love.com:80> Repo Auth
can only be stored to disk unencrypted! You are advised to configure
your system so that Subversion can store passwords encrypted, if
possible. See the documentation for details.
You can avoid future appearances of this warning by setting the value
of the 'store-plaintext-passwords' option to either 'yes' or 'no' in
'/var/www/.subversion/servers'.
-----------------------------------------------------------------------
Store password unencrypted (yes/no)? yes
連續輸入2次 "yes"
root@SVN:/home/web# ls -al www/
drwxr-xr-x 6 www-data www-data 4096 2010-05-30 16:18 .svn
可以看到.svn的權限,userown、goupown都是www-data
2,使用svn update測試,看www-data用戶是否有權限更新。
$ svn update /home/web/www --username svnuser --password svnpasswd
在連續輸入2次"yes"或者"no"之後、可以看到已經更新成功:
Store password unencrypted (yes/no)? At revision 37.
3,在hooks目錄下面的添加一個post-commit腳本文件
#!/bin/sh
REPOS="$1"
REV="$2"
export LANG=en_US.UTF-8
svn update /home/web/www --username svnuser --password svnpasswd
在客戶端commit後報錯
sudo su www-data
$ cd /home/svn/repo/hooks
$ ./post-commit
提示:
Store password unencrypted (yes/no)?
在svn update --help中找到了 --no-auth-cache 這個參數:
--no-auth-cache : do not cache authentication tokens
加上這個參數後終於可以了:
root@SVN:/home/svn/repo/hooks# cat post-commit
#!/bin/sh
REPOS="$1"
REV="$2"
export LANG=en_US.UTF-8
svn update /home/web/www --username svnuser --password svnpasswd --no-auth-cache
參考資料來自:
http://blog.sina.com.cn/s/blog_4c5fc6950100h18b.html
爲了便於排錯,可以將腳本的錯誤輸出、以及版本信息、執行用戶的名稱保存到日誌裏面。
#!/bin/sh
REPOS="$1"
REV="$2"
export LANG=en_US.UTF-8
echo `whoami`,$REPOS,$REV >> /tmp/svn_hooks.log
svn update /home/web/www --username svnuser --password svnpasswd --no-auth-cache 2> /home/web/svn_hook.log