我最近使用 Python 实现了一个post-commit钩子,它扫描同一存储库中的不同项目,然后采取相应的行动。我是 Python 新手,因此以下脚本中可能存在一些效率低下(甚至是完全错误),但它确实适用于我们的目的:
#!/usr/bin/env python
import commands
from subprocess import *
import os
import sys
# This is a post-commit hook. The arguments passed to the hook
# are different than a pre-commit hook, and the syntax/use for
# svnlook will probably be different too.
def check_repo_and_do_stuff(repos, rev):
dirs_changed_cmd =
p1 = Popen('%s dirs-changed %s -r %s' % (SVNLOOK, repos, rev)
dirs_changed = p1.communicate[0]
for line in dirs_changed:
if line.find('/part-of-path-for/project1') >= 0:
do_stuff_for_project1()
if line.find('/part-of-path-for/project2') >= 0:
do_stuff_for_project2()
def do_stuff_for_project1()...
def do_stuff_for_project2()...
SVNLOOK='/usr/bin/svnlook'
# Take the arguments that svnserve passes on the command-line
repos = sys.argv[1]
rev = sys.argv[2]
check_repo_and_do_stuff(repos, rev)
我希望这会有所帮助。
-扎卡里