git で共用レポジトリを作成する
git で subversion 的な共用レポジトリを作成するには。
今までは適当に bare なレポジトリを作成して sgid を設定して、 ユーザの zshenv に umask 002 を設定して、、と面倒なことをしていたが、 --shared オプションをつけてレポジトリを作成すれば良いだけらしい。
$ umask 002
$ mkdir test.git
$ chown -R yuanying:everyone test.git/
$ cd test.git/
$ ll -a
total 0
drwxrwxr-x 2 yuanying everyone 68 11 16 10:52 ./
drwxrwxr-x 8 yuanying staff 272 11 16 10:52 ../
$ git --bare init --shared
Initialized empty shared Git repository in /Users/yuanying/Projects/html/test.git/
$ ll -a
total 24
drwxrwsr-x 9 yuanying everyone 306 11 16 10:53 ./
drwxrwxr-x 8 yuanying staff 272 11 16 10:52 ../
-rw-rw-r-- 1 yuanying everyone 23 11 16 10:53 HEAD
-rw-rw-r-- 1 yuanying everyone 145 11 16 10:53 config
-rw-rw-r-- 1 yuanying everyone 73 11 16 10:53 description
drwxrwsr-x 12 yuanying everyone 408 11 16 10:53 hooks/
drwxrwsr-x 3 yuanying everyone 102 11 16 10:53 info/
drwxrwsr-x 4 yuanying everyone 136 11 16 10:53 objects/
drwxrwsr-x 4 yuanying everyone 136 11 16 10:53 refs/
ちゃんとディレクトリに sgid もついてる。素晴らしい。
$ more config
[core]
repositoryformatversion = 0
filemode = true
bare = true
ignorecase = true
sharedrepository = 1
[receive]
denyNonFastforwards = true
--shared オプションをつけないで作成してしまった後でも、
config ファイルに sharedrepository = 1
を追記すれば良いみたい。
まとめ
レポジトリ作成時の --shared オプションは以下のことをやってくれる。
- レポジトリ内に作られるディレクトリのパーミッションに sgid を付加。
- config ファイルに sharedrepository = 1 を追加。
- ユーザがこの共有レポジトリに push した際に、ファイルのパーミッションを、 グループも読み書きできるようにしてくれる。
- ユーザの .zshenv などに umask を設定する必要が無い。