Skip to content

Instantly share code, notes, and snippets.

@JakeWharton
Created April 9, 2010 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JakeWharton/361182 to your computer and use it in GitHub Desktop.
Save JakeWharton/361182 to your computer and use it in GitHub Desktop.
git post-receive hook for updating Trac 0.12
#!/usr/bin/python
import sys
import subprocess
GIT_PATH = '/usr/bin/git'
TRAC_ADMIN_PATH = '/usr/local/bin/trac-admin'
VALID_BRANCHES = ['master']
TRAC_ENV = '/path/to/trac'
REPO_NAME = 'somerepo'
if __name__ == '__main__':
for line in sys.stdin:
old, new, ref = line.split()
if ref.startswith('refs/heads/') and ref[11:] in VALID_BRANCHES:
args = [new] if old == '0' * 40 else [new, '^' + old]
pending_commits = subprocess.Popen([GIT_PATH, 'rev-list'] + args, stdout=subprocess.PIPE).communicate()[0].splitlines()[::-1]
subprocess.call([TRAC_ADMIN_PATH, TRAC_ENV, "changeset", "added", REPO_NAME] + pending_commits)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment