|Version 62 (modified by 6 years ago) (diff),|
Git Plugin for Trac
- Browsing source code in a Git repository via the TracBrowser
- Viewing the change history of a file or directory using TracRevisionLog
- Performing diffs between any two files or two directories
- Displaying submitted changes in the TracTimeline (0.11)
- (Optionally) caching TracChangeset information in Trac's database (0.11)
- Caching Git commit relation graph in memory (0.11)
- Using the TracSearch page to search change descriptions (0.11)
- Annotation support, also known as "blame" operation (0.11)
- Interpretation of 40-character wide hex-strings as sha1 commit checksums
|GIT||1.4.4+|| 1.5.2+ (for plugin v0.11.0.1) |
1.5.6+ (for plugin v0.11.0.2+)
- nanosleep.org's GitPlugin branch (using trac 0.10)
Sites that were previously using GitPlugin
- The GIT repositories at Fedora Hosted
- GNU Parted
- ReductiveLabs Puppet
- Ohloh Labs
- assignment help
- essay help
As this is for now just a proof of concept implementation, it has quite some deficiencies, some of which exist as tickets already:
...and other potential issues/todos which aren't ticket-tracked yet:
does not highlight sha1sums automatically
- issues with filenames containing newlines (seems to be a Trac bug)
If you have any issues, create a new ticket.
The source code is hosted at GitHub
(An experimental branch of this plugin with a hacky caching feature and some bug fixes is available from here.)
See also generic instructions at trac:TracPlugins
For Trac 0.11:
or alternatively the Python 2.4 backport:
For Trac 0.12
Simply point your Trac instance to a local git repository:
[trac] repository_dir = /var/git/Test.git repository_type = git ## the following settings are only supported for plugin version 0.11 or later [git] ## let Trac cache meta-data via CachedRepository wrapper; default: false cached_repository = true ## disable automatic garbage collection for in-memory commit-tree cache; default: false persistent_cache = true ## length revision sha-sums should be tried to be abbreviated to (must be >= 4 and <= 40); default: 7 shortrev_len = 6 ## (0.12.0.3+) minimum length for which hex-strings will be interpreted as commit ids in wiki context; default: 40 wiki_shortrev_len = 7 ## executable file name (in case of doubt use absolute path!) of git binary; default: 'git' git_bin = /usr/src/git-dev/git ## (0.12.0.5+) define charset encoding of paths stored within git repository; default: 'utf-8' git_fs_encoding = latin1 ## (0.12.0.3+) enable reverse mapping of git email addresses to trac user ids; default: false trac_user_rlookup = true ## (0.12.0.3+) use git-committer id instead of git-author id as changeset owner; default: true use_committer_id = false ## (0.12.0.3+) use git-committer timestamp instead of git-author timestamp as changeset time; default: true use_committer_time = false
Test.gitabove needs to be the
.gitrepository directory (i.e. the one containing the file
config), not the working tree directory that holds the
- Wrong permissions may also be the cause of the error
!GitError: GIT control files not found, maybe wrong directory?
- If you are noticing a slow down in trac with a repository above 500 commits, try disabling the caching. It seems to bog things down as a repo grows.
If installed globally, don't forget to enable the plugin:
[components] # for plugin version 0.10 gitplugin.* = enabled # for plugin version 0.11.0.1+ tracext.git.* = enabled
post-receive hook scripts
For Trac 0.11 see attachments below.
With Trac 0.12 a VC independent plugin approach to handling ticket references in commit messages has been put into place.
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 yourRepository.git/hooks/ along the lines of:
#!/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() 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())
You will also need to change your trac.ini file accordingly. Thus 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. e.g. :
... ... [trac] repository_dir = /path/to/git/repos.git/ ... repository_sync_per_request = ... ... [components] tracext.git.* = enabled tracopt.ticket.commit_updater.committicketreferencemacro = enabled tracopt.ticket.commit_updater.committicketupdater = enabled ... ...
Also make sure that the user executing the trac-admin command has read access to your TRAC_ENV and write access to your trac.log as well as to your trac database.
09/06/2010 I was able to get this running with ubuntu karmic, trac 0.12rc and git version 1.7.1 (served with a gitosis install) after encountering the issue mentioned in bug #5480 ("GitError: GIT control files not found, maybe wrong directory?") with:
chmod o+rx /home/git/repositories/blah-blah.git
12/13/2009 Anyone get this working in a shared hosting environment? I've tried with trac 0.11 and I get errors about it not finding the Git component (I did all the trac.ini stuff). If you have instructions please contact me, codecraig -at- gmail -dot- com ....thanks
15/04/2010 Apparently this does not work at all... At least not for me. trac 0.11. Please file a ticket with a decent problem report, instead of writing random notworkings on the wikipage.
13/07/2010 I've managed to get it to work (at least, for it not to complain about the plugin being missing) by adding:
file = /etc/trac/trac.ini
to the \[inherit\] section of the individual projects' trac.ini. Or, of course, you could probably just configure the plugin for that particular project's trac.ini directly.
Author: Herbert Valerio Riedel
Contributors: Hans Petter Jansson
trac-post-receive-hook.py (7.2 KB) - added by 8 years ago.
post-receive hook for closing and referencing tickets
trac-post-receive-hook.2.py (7.3 KB) - added by 8 years ago.
post-receive hook for closing and referencing tickets
trac-post-receive-hook.3.py (7.5 KB) - added by 8 years ago.
post-receive hook for closing and referencing tickets - now auto-creating git_seen table
trac-post-receive-hook-0.12-only-master.py (895 bytes) - added by 6 years ago.
Old example from main site
trac-post-receive-hook-0.12-new-commits-from-all-branches.py (2.2 KB) - added by 6 years ago.
Add commits from all branches, but only those that are new to the repository. Properly handles many branches in one push. Added version number.
trac-post-receive-hook-0.12-new-commits-from-all-branches-with-logfile.py (2.5 KB) - added by 5 years ago.
Correction of the previous version, and add log file to detect errors.
trac-post-receive-hook.4.py (7.5 KB) - added by 4 years ago.
post-receive hook for closing and referencing tickets - updated to trac 1.0; fixed syntax; removed unused imports
Download all attachments as: .zip