2010年7月20日星期二

trac + git

剛剛在trac裏安裝了gitplugin
如果只是一個project安裝plugin的話很簡單
首先把gitpuluin的source下載回來,裏面有幾個不同版本
我是trac 0.11所以進入0.11目錄裏
執行
python setup.py bdist_egg
在dist目錄下面就會有一個*.egg的檔案
在trac admin裏的plugins介面上傳安裝
之後修改trac.conf,因為是用同一部主機所以是用local repository
repository_dir = /var/git/Test.git
repository_type = git
type當然是git,dir就是git working tree裏的.git目錄
應該是HEAD和config所在的位置
這樣就完成了~
可以在trac看到有Browse Source

trac現在還可以由commit去修改ticket
用的是CommitTicketUpdater plugin
不過要設定一下git repository,編輯.git/hooks下面的post-receive
貼上以下內容:

#!/usr/bin/env python

import sys
from subprocess import Popen, PIPE, call

GIT_PATH = '/usr/bin/git'
BRANCHES = ['master']
TRAC_ENV = '/srv/trac/myproj'
REPO_NAME = '(default)'

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())


這個script是在repository接收到object後執行的
例如push之後在remote server執行,用trac-admin去修改commit
這樣修改以後,可以用commit去修改ticket
例如commit message寫:
make the checkbox in menu non-clickable. Fixed #47.
#47 ticket就知變成closed狀態

熱門文章