在hooks目录下添加一个脚本就ok
#!/usr/bin/env python
#-*- encoding: utf-8 -*-
#########################################################################
# File Name: pre-commit.py
# Author: LookBack
# Email: admin#dwhd.org
# Version:
# Created Time: 2015年09月28日 星期一 18时53分18秒
#########################################################################
#SVN提交前检查钩子
#功能:
# 1、强制填写提交注释,内容10字节以上
# 2、强制注释格式为:xxx:xxx
# 3、提交文件检查,过滤不允许提交的文件
#########################################################################
import sys
import os
import re
def main(argv):
(repos, txn) = argv
badlist = (".*config.php$", ".*/php/cache", ".*test", "config.js$","^.*.db$")
message = "".join(os.popen("/usr/bin/svnlook log '%s' -t '%s'" % (repos, txn)).readlines()).strip()
if len(message) < 10:
sys.stderr.write("请输入本次提交的修改内容,10字节以上.n");
sys.exit(1)
if message.find(':') < 1:
sys.stderr.write("请按规范填写注释,格式为:功能名: 修改说明.n");
sys.exit(1)
changelist = os.popen("/usr/bin/svnlook changed '%s' -t '%s'" % (repos, txn)).readlines()
for line in changelist:
for pattern in badlist:
if re.search(pattern, line):
sys.stderr.write("请不要把 %s 加入版本库.n" % line[1:].strip());
sys.exit(1)
sys.exit(0)
if __name__ == "__main__":
main(sys.argv[1:])
根据系统自带的pre-commit.teml中的内容弄清楚这段脚本的含义:
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)
#
# [STDIN] LOCK-TOKENS ** the lock tokens are passed via STDIN.
#
# If STDIN contains the line "LOCK-TOKENS:n" (the "n" denotes a
# single newline), the lines following it are the lock tokens for
# this commit. The end of the list is marked by a line containing
# only a newline character.