SVN
提交代码时实现强制按固定格式填写
Log
的方法
SVN
本身并不提供这种强制填写
Log
的功能,
而是通过一系列的钩子程序
(
称为
hook
脚
本
)
,
在提交之前
(pre-commit)
、
提交过程中
(start-commit)
、
提交之后
(post-commit)
调用
预定的钩子程序来完成一些附加的功能。
本次我们要实现的是在提交到版本库之前检查用户是否已经按固定格式填写了
Log
,
要
使用
pre-commit
这个钩子程序。打开
SVN
的
repository
目录下的
hook
子目录,有一个
“pre
-
commit.tmpl”文件。
这个文件是一个模板文件,
它告诉了我们如何实现提交前控制。
内容如下:
# The pre-commit hook is invoked before a Subversion txn is
# committed. Subversion runs this hook by invoking a program
# (script, executable, binary, etc.) named 'pre-commit' (for which
# this file is a template), with the following ordered arguments:
#
#
[1]REPOS-PATH (the path to this repository)
#
[2]TXN-NAME (the name of the txn about to be committed)
#
# The default working directory for the invocation is undefined, so
# the program should set one explicitly if it cares.
#
# If the hook program exits with success, the txn is committed; but
# if it exits with failure (non-zero), the txn is aborted, no commit
# takes place, and STDERR is returned to the client. The hook
# program can use the 'svnlook' utility to help it examine the txn.
在一个提交事务执行之前,
SVN
会调用指定的
hook
脚本,
并向该脚本传递了两个参数:
REPOS-PATH
(仓库路径)和
TXN-NAME
(本次事务的事务号)。可以在该脚本中进行一些检
查(比如检查
Log
信息是否填写),如果满足条件则返回
0
;否则返回其它非
0
结果,进而
提交失败。可以通过
svnlook
命令来检查是否已经写了
Log
。
目标:检查提交代码时是否按照以下格式填写了
Log
NGRBUG-xxx: yyy
或者
NGRDEV-xxx: (yyy) zzz
其中,
xxx
为
JIRA
编号,
yyy
为
JIRA
的标题,
zzz
为具体的提交说明。
下面分别就
SVN
服务器搭建在
Windows
上和
Linux
上两种情况下列出
pre-commit
脚本的内
容。
1.
SVN
服务器搭建在
Windows
上
在
hook
目录下创建
pre-commit.bat
文件,内容如下: