ゆーすけべー日記を読んで、そういえばgitのprivate repositoryを持ってないし何かのときのために設定しておくか、と思ってさくらVPSのサーバにgitoliteを入れてみた。
Hosting Git Repositories
以下、手順メモ。
adminになるため公開鍵をコピー
sugyan@remote $ sudo cp $HOME/.ssh/id_dsa.pub /home/git/admin.pub
setup
コピーしてきた公開鍵を使ってsetup。使うコマンドはgl-setup
だけ
sugyan@remote $ su - git git@remote $ gl-setup -q admin.pub creating gitolite-admin... Initialized empty Git repository in /home/git/repositories/gitolite-admin.git/ creating testing... Initialized empty Git repository in /home/git/repositories/testing.git/ [master (root-commit) 9a57094] start 2 files changed, 6 insertions(+), 0 deletions(-) create mode 100644 conf/gitolite.conf create mode 100644 keydir/admin.pub git@remote $ ls repositories/ gitolite-admin.git testing.git
repositoryが出来上がってる。
gitolite-adminをclone
adminとしてgitolite-adminをcloneしてくる。同一サーバ内から持ってくるのでhost名はlocalhost指定で良い
sugyan@remote $ mkdir ~/temp sugyan@remote $ cd ~/temp sugyan@remote $ git clone git@localhost:gitolite-admin Initialized empty Git repository in /home/sugyan/temp/gitolite-admin/.git/ remote: Counting objects: 6, done. remote: Compressing objects: 100% (4/4), done. remote: Total 6 (delta 0), reused 0 (delta 0) Receiving objects: 100% (6/6), done. sugyan@remote $ ls gitolite-admin
cloneできた。
ローカルからも使えるようにする
ローカル環境の公開鍵を持ってきて登録する。
sugyan@local $ scp $HOME/.ssh/id_dsa.pub vps:temp/gitolite-admin/keydir/sugyan-local.pub
再びsshでvpsサーバに入ってgitolite-admin上で公開鍵をaddしてpush
sugyan@local $ ssh vps sugyan@remote $ cd ~/temp/gitolite-admin sugyan@remote $ git status # On branch master # Untracked files: # (use "git add <file>..." to include in what will be committed) # # keydir/sugyan-local.pub nothing added to commit but untracked files present (use "git add" to track) sugyan@remote $ git add keydir/sugyan-local.pub sugyan@remote $ git commit -m 'add sugyan-local' [master a193304] add sugyan-local 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 keydir/sugyan-local.pub sugyan@remote $ git push Counting objects: 6, done. Delta compression using up to 2 threads. Compressing objects: 100% (4/4), done. Writing objects: 100% (4/4), 842 bytes, done. Total 4 (delta 0), reused 0 (delta 0) remote: remote: ***** WARNING ***** remote: the following users (pubkey files in parens) do not appear in the config file: remote: sugyan-local(sugyan-local.pub) To git@localhost:gitolite-admin 9a57094..a193304 master -> master
confに何も書き足していないので警告は出るけど、まぁ今は問題無し。
ローカルから確認。gitolite-adminは権限ないからcloneできないけど、デフォルトでtestingは@allに対してRW+になっているのでcloneできるしpushもできる。
sugyan@local $ git clone git@vps:gitolite-admin Cloning into gitolite-admin... R access for gitolite-admin DENIED to sugyan-local (Or there may be no repository at the given path. Did you spell it correctly?) fatal: The remote end hung up unexpectedly sugyan@local $ git clone git@vps:testing Cloning into testing... warning: You appear to have cloned an empty repository. sugyan@local $ cd testing sugyan@local $ echo hoge > hoge sugyan@local $ git add hoge sugyan@local $ git commit -m 'add hoge' [master (root-commit) 3285627] add hoge 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 hoge sugyan@local $ git push origin master Counting objects: 3, done. Writing objects: 100% (3/3), 205 bytes, done. Total 3 (delta 0), reused 0 (delta 0) To git@vps:testing * [new branch] master -> master
大丈夫げ。
グループとリポジトリを作る
gitolite-adminにてconf/gitolite.conf
を編集。@sugyanというグループを作り、そこにsugyan-localを加える
sugyan@remote $ emacs conf/gitolite.conf sugyan@remote $ git diff diff --git a/conf/gitolite.conf b/conf/gitolite.conf index 2d55bf8..202384a 100644 --- a/conf/gitolite.conf +++ b/conf/gitolite.conf @@ -1,5 +1,10 @@ +@sugyan = sugyan-local + repo gitolite-admin RW+ = admin repo testing RW+ = @all + +repo my-private + RW+ = @sugyan sugyan@remote $ git add conf/gitolite.conf sugyan@remote $ git commit -m 'add new group and repository' [master e3c35ed] add new group and repository 1 files changed, 5 insertions(+), 0 deletions(-) sugyan@remote $ git push Counting objects: 7, done. Delta compression using up to 2 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (4/4), 409 bytes, done. Total 4 (delta 0), reused 0 (delta 0) remote: creating my-private... remote: Initialized empty Git repository in /home/git/repositories/my-private.git/ To git@localhost:gitolite-admin a193304..e3c35ed master -> master
my-private
レポジトリが新しく作成された。
ローカルから確認。
sugyan@local $ git clone git@vps:my-private Cloning into my-private... warning: You appear to have cloned an empty repository. sugyan@local $ cd my-private sugyan@local $ echo fuga > fuga sugyan@local $ git add fuga sugyan@local $ git commit -m 'add fuga' [master (root-commit) 5955bdb] add fuga 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 fuga sugyan@local $ git push origin master Counting objects: 3, done. Writing objects: 100% (3/3), 207 bytes, done. Total 3 (delta 0), reused 0 (delta 0) To git@vps:my-private * [new branch] master -> master
testing同様に読み書きできた。
別のマシンからも使いたい場合は公開鍵を登録して@sugyanグループに追加してやれば良いし、他の人と共同で使うことになれば都度グループなり権限なりを追加していけば良い。
感想
最初なんだかよく分からずちょっと詰まったけど、一度設定できてしまえば結構ラクに管理できて良さそう。もっと細かい権限設定なども出来るらしい。必要になったら調べて設定してみよう