码迷,mamicode.com
首页 > 其他好文 > 详细

SVN钩子运用

时间:2015-06-16 14:50:38      阅读:331      评论:0      收藏:0      [点我收藏+]

标签:svn钩子

一、Svn钩子脚本简介

钩子脚本的具体写法就是操作系统shell脚本程序写法,请根据自己SVN所在的操作系统和shell程序进行相应的开发。


钩子脚本就是被某些版本库事件触发的程序,例如创建新版本或修改未被版本控制的属性。每个钩子都能掌管足够的信息来了解发生了什么事件,操作对象是什么以及触发事件用户的账号。根据钩子的输出或者返回状态,钩子程序能够以某种方式控制该动作继续执行,停止或者挂起。


svn的hooks模版功能介绍

start-commit 提交前触发事务

pre-commit 提交完成前触发事务

post-commit 提交完成时触发事务

pre-revprop-change 版本属性修改前触发事务

post-revprop-change 版本属性修改后触发事务


post-commit

在提交完成,成功创建版本之后执行该钩子,提交已经完成,不可更改,因此脚本返回值被忽略


post-lock

对文件进行加锁操作之后执行该脚本


post-revprop-change

在修改revision属性之后,执行该脚本。因为修改稿已经完成,不可更改,因此本脚本的返回值被饭忽略

(不过实际上的实现似乎是该脚本的正确执行与否影响属性修改)


post-unlock

对文件进行解锁操作之后执行该脚本


pre-commit

在Subversion transaction完毕之后,在提交之前,执行该脚本


pre-revprop-change

在修改revision属性之前,执行该脚本


start-commit

对客户端还没有向服务器提交数据之前,即还没有建立Subversion transaction(缩写txn)之前,执行该脚本


默认情况下,钩子的子目录中包含各种版本库钩子模板

[root@svn ~]# ls -l /application/svndata/sadoc/hooks/

总用量 36

-rw-r--r-- 1 root root 1977 6月  15 16:42 post-commit.tmpl

-rw-r--r-- 1 root root 1638 6月  15 16:42 post-lock.tmpl

-rw-r--r-- 1 root root 2289 6月  15 16:42 post-revprop-change.tmpl

-rw-r--r-- 1 root root 1567 6月  15 16:42 post-unlock.tmpl

-rw-r--r-- 1 root root 3426 6月  15 16:42 pre-commit.tmpl

-rw-r--r-- 1 root root 2410 6月  15 16:42 pre-lock.tmpl

-rw-r--r-- 1 root root 2786 6月  15 16:42 pre-revprop-change.tmpl

-rw-r--r-- 1 root root 2100 6月  15 16:42 pre-unlock.tmpl

-rw-r--r-- 1 root root 2780 6月  15 16:42 start-commit.tmpl


[root@svn hooks]# cp post-commit.tmpl post-commit

[root@svn hooks]# vim post-commit

REPOS="$1"

REV="$2"


mailer.py commit "$REPOS" "$REV" /path/to/mailer.conf

touch /tmp/$(date +%MS).log



[root@svn hooks]# chmod 755 post-commit


二、在客户端下

在D:\oldboy\trunk\test\tom.txt

技术分享

                      技术分享

技术分享

技术分享

四、在返回svn服务器

    提交完成,触发程序,在/tmp下多了日志文件

[root@svn hooks]# ll -lrt /tmp

总用量 16

drwx------. 2 root root 16384 4月  24 17:56 lost+found

-rw-r--r--  1 root root     0 6月  16 11:04 04S.log

-rw-r--r--  1 root root     0 6月  16 11:04 0452.log

-rw-r--r--  1 root root     0 6月  16 11:06 0644.log

-rw-r--r--  1 root root     0 6月  16 11:12 1224.log

-rw-r--r--  1 root root     0 6月  16 11:15 1548.log



五、钩子脚本post-commit



REPOS="$1"

TXN="$2"

#此处更改大小限制,这里是5M

MAX_SIZE=5242880

#此处增加限制文件后比缀名

FILTER=‘\.(zip|rar|o|obj|tar|gz)$‘

#Make sure that the log message contains some test


SVNLOOK=/usr/bin/svnlook


#LOGMSG=`$SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" | wc -c`

LOGMSG=`$SVNLOOK log -t "$TXN" "$REPOS" | wc -c`


if [ "$LOGMSG" -lt 9 ];

then

        echo -e "nLog message cann‘t be empty! you must input more than 8 chars as comment!." 1>&2

exit 1

fi


files=$($SVNLOOK changed -t $TXN $REPOS |cut -d "" -f 4-)

#echo "$files">&2

#echo "$r">&2

#exit 1


rc=0


echo "$files" | while read f;

do

#check file type


filesize=`$SVNLOOK cat -t "$TXN" "$REPOS" "$f" | wc -c `


if [ "filezie" -gt "$MAX_SIZE" ];

then

        echo "File $f is too large(must <+$MAX_SIZE)B" >&2

        exit 1

fi

done

#All checks passed,so allow the commit.

if [ $? -eq 1 ];

then

exit 1

else

exit 0

fi


本文出自 “散人” 博客,请务必保留此出处http://zouqingyun.blog.51cto.com/782246/1662285

SVN钩子运用

标签:svn钩子

原文地址:http://zouqingyun.blog.51cto.com/782246/1662285

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!