共有のgitリポジトリを提供するためにgitosisを設置したのでメモ。

初期設定

まずパッケージをインストールする。

% sudo apt-get install gitosis

Debianの場合、ユーザgitosisはパッケージが用意してくれる。自分で用意す るときはREADME.rst.gzを参照。

次にgitosis-initを使って管理用データベースgitosis-admin.gitを用意する。 その際に管理人の公開鍵で初期化する。

% sudo -H -u gitosis gitosis-init < GITOSIS_ADMIN.pub

なおgitosis-initは鍵の末尾に書かれた文字列をユーザ名として流用するので注意。

これで/srv/gitosis/repositories/gitosis-admin.git/が作られ初期化される。 ここまではgitosisを動かすホスト上での話。

プロジェクトの初期設定

管理用DBを手元にcloneする。

% git clone gitosis@example.org:gitosis-admin.git

全体の設定ファイルであるgitosis-admin/gitosis.confを編集する。

% cd gitosis-admin
% $EDITOR gitosis.conf
% git diff
--- a/gitosis.conf
+++ b/gitosis.conf
@@ -4,3 +4,10 @@
 writable = gitosis-admin
 members = johnd

+[group foo-developers]
+writable = foo
+members = jdoe rroe
+
+[group foo-builders]
+readonly = foo
+members = hudson
%

終わったら変更をcommitして、pushして有効にする。

% git commit -am 'Add project Foo.'
% git push

リポジトリを作る

gitosisの管理下に普通のリポジトリを作るには、どこかで用意したものをpush する必要がある。

% mkdir foo; cd foo; git init
% echo foo >README; git add README; git commit -m 'Add README'

用意できたらpushする。

% git push --dry-run \
  gitosis@example.com:foo.git master:refs/heads/master
% git push gitosis@example.com:foo.git master:refs/heads/master

push先ブランチ(master:refs/heads/master)を指定する必要があるので注意。

プロジェクトにメンバーを追加する

管理人は、プロジェクトメンバーに公開鍵を送ってもらい、gitosis-admin.gitに 登録する。

% $EDITOR gitosis.conf
[group foo-developers]
...
members = jdoe rroe johnd
...
% cat > keydir/johnd.pub
% git add keydir/johnd.pub
% git commit -am 'Add johnd to foo.'
% git push

gitosis.confのmembersで指定した名前は、keydir/*.pubのbasenameと一致してい れば問題ない。

コミット通知をメーリングリストに送信するよう設定

いわゆるコミット通知(push通知)がメーリングリストに流れるように設定し たいので、gitosis管理下のリポジトリでpost-receiveフックを設定する。

% lv /srv/gitosis/repositories/foo.git/hooks/post-receive
% lv /usr/share/doc/git-core/contrib/hooks/post-receive-email

hooks.mailinglistとhooks.envelopesenderを設定する。diffまで含めたければ hooks.showrevに"git show -C %s; echo"を設定すればよいらしい。

% su
# cd /srv/gitosis/repositories/foo.git
# git config hooks.mailinglist "foo@lists.example.com"
# git config hooks.envelopesender "gitosis@example.com"
# git config hooks.showrev "git show -C %s | nkf --utf8; echo"
# exit
% sudo $EDITOR /srv/gitosis/repositories/foo.git/hooks/post-receive
. /usr/share/doc/git-core/contrib/hooks/post-receive-email
% sudo chmod +x /srv/gitosis/repositories/foo.git/hooks/post-receive
%
% sudo vi /srv/gitosis/repositories/foo.git/description
Foo
%

descriptionの編集を忘れずに。

gitのバージョンが古いと、付属のpost-receive-emailがhooks.showrevをサポー トしていないことがある。lennyは注意。

メール本文とdiffのエンコーディングを合わせるためにnkfでdiffをUTF-8に変換 している。本当はpost-receive-emailにUTF-8がハードコードされてるのをなんと かして、全体をiso-2022-jpとかにすべき。

参加者側の作業

プロジェクトに参加するメンバーは、管理人に公開鍵を送って登録してもらった ら、あとは普通にcloneしてpush/pullすればいい。

% git clone gitosis@example.com:foo.git

ポートを指定したいときは次の形式で。

git clone ssh://gitosis@example.com:10022/foo.git

sshに細かい設定を渡したいときは、sshをラップするシェルスクリプトを書いて 変数GIT_SSHで指定する手がある。詳しくはgit-clone(1)参照。

% cat ssh-as-jdoe
#!/bin/sh
ssh -i ~/.ssh/id_rsa_jdoe $1 $2
%
% GIT_SSH=ssh-as-jdoe git clone gitosis@example.com:foo.git

うまくいかなかったら、sshレベルでアクセスできているか確認。

% ssh -v gitosis@example.com
...
debug1: Remote: Forced command: gitosis-serve johnd
...
Enter passphrase for key '/home/johnd/.ssh/id_rsa':

gitosisまでつながっていれば、こんなふうに出力されてるはず(この後切断され る)。

その他

  • うまくいかないときはtcpdの設定にも注意。

    % grep -i sshd /etc/hosts.*
    ...
    /etc/hosts.deny:sshd: ALL
    ...
    

    うっかりミス。

資料