Changes between Version 69 and Version 70 of GitPlugin


Ignore:
Timestamp:
Nov 29, 2010, 1:43:37 PM (4 years ago)
Author:
silk
Comment:

Added an example post-receive hook that adds changesets from all branches

Legend:

Unmodified
Added
Removed
Modified
  • GitPlugin

    v69 v70  
    130130
    131131With Trac 0.12 a VC independent plugin approach to handling ticket references in commit messages has been put into place.
    132 Thus for 0.12 in you basically need to enable the !CommitTicketUpdater component in `trac.ini` or via the webinterface under 'Admin/Plugins'. Additionally you have to call `trac-admin TRAC_ENV changeset added <commitid(s)>`, e.g. by putting a `post-receive` script into `your_repository.git/hooks/` along the lines of:
    133 {{{
    134 #!python
    135 #!/usr/bin/env python
     132Thus for 0.12 in you basically need to enable the !CommitTicketUpdater component in `trac.ini` or via the webinterface under 'Admin/Plugins'. Additionally you have to call `trac-admin TRAC_ENV changeset added <commitid(s)>`, e.g. by putting a `post-receive` script into `your_repository.git/hooks/`.
    136133
    137 import sys
    138 from subprocess import Popen, PIPE, call
     134Two examples are available as attachments.
    139135
    140 GIT_PATH = '/usr/bin/git'
    141 BRANCHES = ['master']
    142 TRAC_ENV = '/srv/trac/myproj'
    143 REPO_NAME = '(default)'
     136[attachment:trac-post-receive-hook-0.12-new-commits-from-all-branches.py] - example that adds to Trac all commits, ensuring that every commit is added only once.
    144137
    145 def call_git(command, args):
    146     return Popen([GIT_PATH, command] + args, stdout=PIPE).communicate()[0]
     138[attachment:trac-post-receive-hook-0.12-only-master.py] - old example from this site, that adds to Trac only commits to the master branch
    147139
    148 def handle_ref(old, new, ref):
    149     # If something else than the master branch (or whatever is contained by the
    150     # constant BRANCHES) was pushed, skip this ref.
    151     if not ref.startswith('refs/heads/') or ref[11:] not in BRANCHES:
    152         return
    153 
    154     # Get the list of hashs for commits in the changeset.
    155     args = (old == '0' * 40) and [new] or [new, '^' + old]
    156     pending_commits = call_git('rev-list', args).splitlines()[::-1]
    157 
    158     call(["trac-admin", TRAC_ENV, "changeset", "added", REPO_NAME] + pending_commits)
    159 
    160 if __name__ == '__main__':
    161     for line in sys.stdin:
    162         handle_ref(*line.split())
    163 }}}
    164140You will also need to change your trac.ini file accordingly.
    165141Thus repository_sync_per_request under the trac section is to be unset, and tracopt.ticket.commit_updater.* under component are to be set to enabled.