我正在尝试编写一个提交后挂钩,我在映射驱动器 (V:) 上有一个 Git 存储库,msysgit 安装在 C:\Git 中,Python 安装在 C:\Python26 中。
我在 Windows 7 64 位上运行 TortoiseGit。
脚本是:
#!C:/Python26/python
import sys
from subprocess import Popen, PIPE, call
GIT_PATH = 'C:\Git\bin\git.exe'
BRANCHES = ['master']
TRAC_ENV = 'C:\TRAC_ENV'
REPO_NAME = 'core'
def call_git(command, args):
return Popen([GIT_PATH, command] + args, stdout=PIPE).communicate()[0]
def handle_ref(old, new, ref):
# If something else than the master branch (or whatever is contained by the
# constant BRANCHES) was pushed, skip this ref.
if not ref.startswith('refs/heads/') or ref[11:] not in BRANCHES:
return
# Get the list of hashs for commits in the changeset.
args = (old == '0' * 40) and [new] or [new, '^' + old]
pending_commits = call_git('rev-list', args).splitlines()[::-1]
call(["trac-admin", TRAC_ENV, "changeset", "added", REPO_NAME] + pending_commits)
if __name__ == '__main__':
for line in sys.stdin:
handle_ref(*line.split())
如果我从命令行运行“git commit ...”命令,它似乎根本没有运行钩子脚本。