Tracサーバで複数のgitリポジトリを管理

Tracには0.12から1つのTracインスタンスで複数リポジトリを管理する機能が入っている(MultipleRepositorySupport – The Trac Project)。

これを使って複数のgitリポジトリを管理できるようにしてみた。

git pluginを入れる

gitを有効にするにはGitPlugin – Trac Hacks - Plugins Macros etc.を入れる必要がある。

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

こんだけ。

trac.iniの設定

git pluginの有効化
[components]
# for plugin version 0.11.0.1+                                                                                             
tracext.git.* = enabled
git pluginの詳細設定

git_binの絶対パス指定は必須っぽい。

[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 = 7

## (0.12.0.3+) minimum length for which hex-strings will be interpreted as commit ids in wiki context; default: 40         
wiki_shortrev_len = 40

## executable file name (in case of doubt use absolute path!) of git binary; default: 'git'                                
git_bin = /usr/bin/git

## (0.12.0.5+) define charset encoding of paths stored within git repository; default: 'utf-8'                             
git_fs_encoding = utf-8

## (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 = true

## (0.12.0.3+) use git-committer timestamp instead of git-author timestamp as changeset time; default: true                
use_committer_time = true
メインリポジトリの設定

メインリポジトリとセカンダリリポジトリみたいな扱いになるので、複数管理したい場合もこっちをきちんと設定する必要がある。

最初ここをデフォルト値で放置してたらリポジトリブラウザ自体が出てこなかった。

[trac]
〜中略〜
repository_dir = /var/trac/git/default.git/
repository_sync_per_request = (default)
repository_type = git
セカンダリリポジトリの設定
[repositories]
hoge.dir = /var/trac/git/hoge.git/
hoge.type = git
huga.dir = /var/trac/git/huga.git/
huga.type = git
デバッグログの設定

設定が何かおかしい時にはこれを有効にして、ログを読む必要がある。

[logging]
log_file = trac.log
log_level = DEBUG
log_type = file

gitリポジトリの作成

# mkdir /var/trac/git
# chown www-data:www-data /var/trac/git
# sudo -u www-data git init --bare default.git
# sudo -u www-data git init --bare hoge.git
# sudo -u www-data git init --bare huga.git
# cd default.git
# sudo -u www-data git update-server-info
# cd ../hoge.git
# sudo -u www-data git update-server-info
# cd ../huga.git 
# sudo -u www-data git update-server-info

resyncテスト

# trac-admin /var/trac/projects/<project name> repository resync '(default)'
# trac-admin /var/trac/projects/<project name> repository resync 'hoge'
# trac-admin /var/trac/projects/<project name> repository resync 'huga'

trac.iniが間違えてたりgitリポジトリが壊れて無ければresyncが成功するはず。

tracテスト

# /etc/init.d/apache2 restart

tracの画面を確認してリポジトリブラウザがちゃんと動いているか確認。
ダメならログを読んで設定を直す。

WebDAV経由のgitリポジトリ

# a2enmod dav_fs
# a2enmod dav
# a2enmod dav_lock
# emacs /etc/apache2/sites-available/<site>

tracの認証用に設定しておいたhtdigestを流用してみる。
本当はリポジトリ毎に管理したほうがいいかもしれない。

    Alias /git /var/trac/git
    <Location /git>
              Options Indexes
              DAV on
              AuthType Digest
              AuthName "git repository"
              AuthDigestDomain /git/
              AuthDigestProvider file
              AuthUserFile /var/trac/projects/<project name>/htdigest
              <Limitexcept GET PUT DELETE MOVE COPY HEAD PROPFIND OPTIONS REPORT MKCOL LOCK UNLOCK>
                      Require valid-user
              </Limitexcept>
    </Location>
# /etc/init.d/apache2 restart

クライアントからテストしてみる。

$ git clone https://server/git/hoge.git
$ cd hoge
$ echo test > test
$ git add test
$ git commit -a -m "add test"
$ git push origin master

ちゃんとclone, pushが動くのを確認する。
ダメならApacheのログを確認。