| 99 | === post-receive hook scripts === |
| 100 | |
| 101 | For Trac 0.11 see attachments below. |
| 102 | |
| 103 | With Trac 0.12 a VC independent plugin approach to handling ticket references in commit messages has been put into place. |
| 104 | Thus for 0.12 in you basically need to enable the CommitTicketUpdater component in `trac.ini`, and call `trac-admin TRAC_ENV changeset added <commitid(s)>`, e.g. by using a `post-receive` script along the lines of: |
| 105 | {{{ |
| 106 | #!python |
| 107 | #!/usr/bin/env python |
| 108 | |
| 109 | import sys |
| 110 | from subprocess import Popen, PIPE, call |
| 111 | |
| 112 | GIT_PATH = '/usr/bin/git' |
| 113 | BRANCHES = ['master'] |
| 114 | TRAC_ENV = '/srv/trac/myproj' |
| 115 | REPO_NAME = '(default)' |
| 116 | |
| 117 | def call_git(command, args): |
| 118 | return Popen([GIT_PATH, command] + args, stdout=PIPE).communicate()[0] |
| 119 | |
| 120 | def handle_ref(old, new, ref): |
| 121 | # If something else than the master branch (or whatever is contained by the |
| 122 | # constant BRANCHES) was pushed, skip this ref. |
| 123 | if not ref.startswith('refs/heads/') or ref[11:] not in BRANCHES: |
| 124 | return |
| 125 | |
| 126 | # Get the list of hashs for commits in the changeset. |
| 127 | args = (old == '0' * 40) and [new] or [new, '^' + old] |
| 128 | pending_commits = call_git('rev-list', args).splitlines()[::-1] |
| 129 | |
| 130 | call(["trac-admin", TRAC_ENV, "changeset", "added", REPO_NAME] + pending_commits) |
| 131 | |
| 132 | if __name__ == '__main__': |
| 133 | for line in sys.stdin: |
| 134 | handle_ref(*line.split()) |
| 135 | }}} |
| 136 | |