« 显示文件的倒数XX行 | Main | webwork.properties的完整翻译 »
Subversion提供了一种叫做"Hook"的东西,当然对于开发人员来说这很熟悉的概念了.
Subversion提供的Hook支持多种语言/脚本,例如shell脚本,python,perl,exe等等
我们暂且不管其他步骤的Hook,我们只研究这个提交前的检测,在Subversion中叫做"pre-commit" ,默认Subversion提供了一些hook的模板,位于每个仓库的hooks目录下,打开模板可以看到默认提供了一些功能,按照自己的需要修改即可.
例如我的Subversion服务是用Apache做验证的,那么就需要去掉相关的验证.
为了用户用户,还需要加上自己的一些信息提示,告诉用户为什么不能提交成功.
默认的pre-commit部分内容是这样的:
REPOS="$1" TXN="$2" # Make sure that the log message contains some text. SVNLOOK=/app/subversion/bin/svnlook $SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" > /dev/null || exit 1 # Check that the author of this commit has the rights to perform # the commit on the files and directories being modified. commit-access-control.pl "$REPOS" "$TXN" commit-access-control.cfg || exit 1 # All checks passed, so allow the commit. exit 0
从pre-commit.tmpl的最上一行(这里没贴出),可以知道这个是shell脚本.
检测的步骤主要包括:
于是我们开始动手术,总之很简单吧,不过也遇到很多问题,几个主要关键点在于:
我开始是这样写的:
$SVNLOOK log -t "$TXN" "$REPOS" | egrep "[^[:space]]+" > /dev/null || (echo "You must input some comment" >&2;exit 1;)
可惜就是不知道为什么不行,总是提交成功,似乎 exit 1没有被执行.
最后改成了这样,更方便一点了,可以随意添加内容:
#!/bin/sh REPOS="$1" TXN="$2" RES="OK" # Make sure that the log message contains some text. SVNLOOK=/app/subversion/bin/svnlook $SVNLOOK log -t "$TXN" "$REPOS" | egrep "[^[:space:]]+" >/dev/null || unset RES if [ "$RES" != "OK" ] then echo "You must input some comments for you commit" >&2 exit 1 fi # All checks passed, so allow the commit. exit 0
把这个文件命名为pre-commit,放在仓库的hooks目录下,文件的拥有者为仓库目录的拥有者,改为可以执行的权限.
然后试试提交吧,写备注和不写备注,是否ok?
windows 下面怎么弄呢,谢谢
| « | 七月 2008 | » | ||||
|---|---|---|---|---|---|---|
| 一 | 二 | 三 | 四 | 五 | 六 | 日 |
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 | |||