wiki:GitPlugin

Version 42 (modified by anonymous, 5 years ago) (diff)

--

Git Plugin for Trac

Description

This is yet another plugin for Trac 0.10/0.11 which enables GIT to be used instead of Subversion for the trac:VersioningSystemBackend

Features

  • 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
  • ...

Requirements

0.10 Plugin 0.11 Plugin/0.11-py2.4 Plugin 0.12 Plugin
Trac 0.10.x 0.11.x 0.12dev (trunk)
Python 2.4+ 2.5+/2.4+ 2.5+
GIT 1.4.4+ 1.5.2+ (for plugin v0.11.0.1)
1.5.6+ (for plugin v0.11.0.2+)
1.5.6+

Example Sites

Sites that were previously using GitPlugin

Bugs/Feature Requests

As this is for now just a proof of concept implementation, it has quite some deficiencies, some of which exist as tickets already:

#746
Improve performance of GitPlugin
#2633
It should be possible to see the branch in the timeline and for each changeset
#2685
shortrev_len does not work
#4227
Cannot detect GIT version: All git commands result in git usage output which is unparsable.
#4318
Enhance Documentation
#4505
Resetting HEAD on a remote branch causes GitPlugin to complain of missing changeset
#5357
UnicodeDecodeError on UTF-8 encoded filenames
#6398
Internal error if ticket text references SVN-like revision number (changeset)
#7381
GitError: GIT control files not found, maybe wrong directory?
#7665
post-receive hook is not working when default repository is speciefied
#7860
Browse branches as virtual top-level folders
#8016
File rename not supported
#8087
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 5-7: invalid data
#8102
Can't install plugin properly.
#8260
Browse with 'bare' repository fails
#8354
Invalid changeset link in ticket comments is produced by the post-receive-hook for multiple git repositories
#8401
filedescriptor out of range
#8465
Trac[git_fs] ERROR: GitError: Could not retrieve GIT version
#8473
Problem with Trac 0.12.2 and GitPlugin (BrowserModule)
#8522
Browse Source defaults to HEAD, I'd like to be able to specify a branch instead
#8639
PyGIT._get_branches fails with ValueError on commit messages with line feeds
#8658
missing links in messages
#8844
«No changeset HEAD in the repository»
#8880
Support for submodules in source browsing
#8944
Problem with cyrillic file name. (UnicodeDecodeError: 'utf8' codec can't decode)
#9134
git post-receive hook - remote: error: command not found
#9552
TypeError: 'NoneType' object is not subscriptable
#9560
GitPlugin not loading, error in git_fs.py:415
#9581
'Popen' object has no attribute 'terminate'
#9641
Source browser fails with SMB hosted git repository
#9646
WindowsError: (5, 'Access is denied')
#9657
GitPlugin crashed under Win7 while using cygwin
#9778
OSError: [Errno 10] No child processes
#9879
GitNode *must* throw NoSuchNode on invalid revisions for Bitten to work
#10151
GitPlugin on Trac 0.12 with Python 2.4
#10460
some problem with TRAC 0.12 and GIT 1.7.10.2 (Apple Git-33)
#11056
TypeError: execv() arg 2 must contain only strings

...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)
  • ...

Existing bugs and feature requests for GitPlugin are here (all including closed ones are here).

If you have any issues, create a new ticket.

Download, Source

Download the zipped source, check out GitPlugin from Subversion, or browse the source.

(An experimental branch of this plugin with a hacky caching feature and some bug fixes is available from here.)

Install

See also generic instructions at trac:TracPlugins

If you have a recent setuptools version installed, you can directly install GitPlugin from the Subversion repository.

For Trac 0.11:

easy_install http://trac-hacks.org/svn/gitplugin/0.11

or alternatively the Python 2.4 backport:

easy_install http://trac-hacks.org/svn/gitplugin/0.11-py2.4

For Trac 0.12

easy_install http://trac-hacks.org/svn/gitplugin/0.12

Configuration

Simply point your Trac instance to a local git repository:

[trac]
repository_dir = /var/git/Test.git
repository_type = git

## the following is only for the 0.11 branch
[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

## executable file name (optionally with path) of git binary; default: 'git'
git_bin = /usr/src/git-dev/git

/!\ NOTE: the Test.git above needs to be the .git repository directory (i.e. the one containing the file HEAD and config), not the working tree directory that holds the .git/ folder.

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, and call trac-admin TRAC_ENV changeset added <commitid(s)>, e.g. by using a post-receive script 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()[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())

Help

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

Recent Changes

[7757] by hvr on 2010-03-07 18:16:57
GitPlugin: ported code from TracMercurial in trac:changeset:6461
[7756] by hvr on 2010-03-07 17:13:38
minor logging tweak
[7755] by hvr on 2010-03-07 14:00:01
GitPlugin: decode git paths to unicode strings; fixes #5357

Author/Contributors

Author: Herbert Valerio Riedel
Contributors: Hans Petter Jansson

Attachments (7)

Download all attachments as: .zip