wiki:GitPlugin

Version 76 (modified by juanf.jaramillo@…, 3 years ago) (diff)

Adding some comments to the hook part

Git Plugin for Trac

Description

This is yet another plugin for Trac 0.10/0.11/0.12/0.13dev 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
  • ...

Example Sites

Requirements

Branch trac-0.10 trac-0.11/trac-0.11-py24 master
Trac 0.10.x 0.11.x 0.12.x/0.13dev
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+

Bugs/Feature Requests/Contributions

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

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

If you have any issues, create a new ticket.

Help is highly appreciated, since I have very little spare time these days as can be seen in the commit history. Feel free to fork GitPlugin on GitHub and improve or fix things.

Source Code

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

Installation

To install GitPlugin, grab a copy of it, and then follow the generic instructions at trac:TracPlugins

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

For Trac 0.11:

easy_install http://github.com/hvr/trac-git-plugin/tarball/trac-0.11

or alternatively the Python 2.4 backport:

easy_install http://github.com/hvr/trac-git-plugin/tarball/trac-0.11-py24

For Trac 0.12

easy_install http://github.com/hvr/trac-git-plugin/tarball/master

Note

This is a rare case where pip is probably more of a hassle than easy_install. pip, by design, does not generate the .egg file for you, which Trac needs.

Configuration

See also wiki:TracIni#git-section of your current Trac installation (if GitPlugin is enabled), for an up-to-date list of customizable [git] settings.

Simply point your Trac instance to a local git repository, and configure your TracIni:

[trac]
# simple single-repository configuration
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

Multi-Repository Configuration

Starting with Trac 0.12, GitPlugin gained support for multi-repository configuration (see also T:TracRepositoryAdmin for generic instructions)

TODO: write about current issues wrt GitPlugin and how to workaround them

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 your_repository.git/hooks/. Won't work as intended before #7301 is fixed.

Two examples are available as attachments.

trac-post-receive-hook-0.12-only-master.py - example that adds to Trac only commits to the master (or other specified) branch

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.

trac-post-receive-hook-0.12-new-commits-from-all-branches-with-logfile.py - the previous one, but with a little change in the REPO_NAME, and adding a log file to detect error. I have no test it with others repositories differents to the default one. I suggets that use one of the two post-receive files, take in consideration the use's grand of exec (I suggets in debian use an user git that belong to the group www-data):

To test post-receive

#!/bin/sh

/srv/git/myrepo.git/hooks/trac-post-receive-hook-0.12-new-commits-from-all-branches-with-logfile.py &> /tmp/tracgitplugin.log

Definitive post-receive

#!/bin/sh

/srv/git/myrepo.git/hooks/trac-post-receive-hook-0.12-new-commits-from-all-branches-with-logfile.py &> /dev/null

Its is important that your git user have access to read the trac.ini and his directory, and also modify access to the trac.db file and his directory as well. This is made by adding the git to the apache2 group (in debian www-data group). If you use log file configured in your trac.ini, it is important that the user have the modify grand also, and the directory as well.

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.

Troubleshooting

/!\ NOTES :

  • the Test.git in the configuration section 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.
  • Wrong permissions may also be the cause of the error !GitError: GIT control files not found, maybe wrong directory?. Make sure the repository_dir argument is accessible via git by the tracd process.
  • 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 
    
  • If on Trac 0.12 you don't see the shortrev and commit branch, you probably have caching enabled (cached_repository = true, persistent_cache = true). Set those to false.

Recent Changes

See Commit History @ GitHub

Author/Contributors

Author: Herbert Valerio Riedel
Contributors: Hans Petter Jansson, Juan Fernando Jaramillo

Attachments (7)

Download all attachments as: .zip