本次我们要实现的是在提交到版本库之前检查用户是否已经写了注释,当然要使用pre-revprop-change这个钩子程序。我们打开SVN的repository下的hook目录,可以发现有好几个文件,其中一个是“pre-revprop-change.tmpl”。这个文件是一个模板文件,它告诉了我们如何实现提交前控制。打开该模板文件,我们看到如下一段说明: # PRE-REVPROP-CHANGE HOOK # # The pre-revprop-change hook is invoked before a revision property # is added, modified or deleted. Subversion runs this hook by invoking # a program (script, executable, binary, etc.) named 'pre-revprop-change' # (for which this file is a template), with the following ordered # arguments: # # [1] REPOS-PATH (the path to this repository) # [2] REVISION (the revision being tweaked) # [3] USER (the username of the person tweaking the property) # [4] PROPNAME (the property being set on the revision) # [5] ACTION (the property is being 'A'dded, 'M'odified, or 'D'eleted) # # [STDIN] PROPVAL ** the new property value is passed via STDIN. # # If the hook program exits with success, the propchange happens; but # if it exits with failure (non-zero), the propchange doesn't happen. # The hook program can use the 'svnlook' utility to examine the # existing value of the revision property. 例子: //本例子可实现允许用户修改Subversion日志。但不是很好:因为一个用户可以修改其他用户的日记 REPOS="$1" REV="$2" USER="$3" PROPNAME="$4" ACTION="$5" if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:log" ]; then exit 0; fi //只是提交的是修改动作,而且是类型log的才返回0(也是就成功) echo "Changing revision properties other than svn:log is prohibited" >&2 exit 1 //改进版 REPOS="$1" REV="$2" USER="$3" PROPNAME="$4" ACTION="$5" SVNLOOK=/usr/bin/svnlook if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:log" ]; then { $SVNLOOK author $REPOS -r $REV | grep $USER ||exit 1 //匹配用户名 exit 0; } fi echo "Changing revision properties other than svn:log is prohibited" >&2 exit 注意:在Linux下需要将pre-revprop-change.tmpl改正成pre-revprop-change 在windows下需要将pre-revprop-change.tmpl改正pre-revprop-change.bat
|