gitリポジトリをhttpで公開する

githubで公開したくないけど、httpでリポジトリを見れるようにしたい事がある。プライベートなプロジェクトだったり、ファイルサイズが巨大だったり。そういう時gitweb.cgiを使う。


こういう風にgitwebでリポジトリを公開したい
http://git.kernel.org/


参考

gitweb.cgiを設定するとリポジトリ名一覧とそれらのコミットログだけはhttpで公開できる。

sudo apt-get install gitweb
sudo mkdir /var/www/git
sudo cp /usr/lib/cgi-bin/gitweb.cgi /var/www/git/index.cgi


/etc/gitweb.conf を編集、#$projectroot = "/var/cache/git"; をコメントアウト


/var/www/git/index.cgi を編集

our $projectroot = "/home/shokai/src/path/to/project";

projectroot で指定されているディレクトリから下へ $project_maxdepth 分だけ辿って全部表示してくれる。
maxdepthは2007になっていた。そんなに掘らないだろ・・


apacheは、perlcgiが動くように設定してあればいい。


これでhttpでcommit logだけ見れるが、clone/pullはできない。
できるようにするには、gitリポジトリの.gitディレクトリがhttpdで公開すればいい。


シンボリックリンクはった。

sudo ln -s /home/shokai/src/path/to/project/ /var/www/git/myproject/

あとリポジトリ内で

git update-server-info

す。これでclone/pullできる。


cloneする

git clone http://shokai.org/git/myproject/.git


Basic認証をかけておくと、git cloneした時に401エラーになる。URLにユーザ名を入れればいい

git clone http://username@shokai.org/git/myproject/.git

パスワードはコマンド後に聞かれる。
username:password@hostname にしてもいいが、当然 .git/config の中にパスワードが平文で保存される。


http://git.kernel.org/ の各リポジトリを見ると、cloneするためのURLが書いてある。
これを表示するには、.git ディレクトリ内に cloneurl というテキストファイルを作ってそこにURLを改行区切りで書けばいい。
gitweb.cgiの1624行目あたりで読み込んでいた。



webdavで.gitディレクトリに書き込めるようにすればpushもできるようになるらしい。


gitwebで公開している(update-server-infoしている)リポジトリに、ssh経由でpushした時

*** Project description file hasn't been set

というエラーがでる。
.git/description を編集してプロジェクト概要を書くとpushできるようになる。


もしくは、 .git/hook/update を編集して、
"Unnamed repository; edit this file to name it for gitweb."
があるあたりにpushを止めてる処理があるのでコメントアウトする
http://stackoverflow.com/questions/700941/git-says-project-description-file-hasnt-been-modified-even-when-it-is-actually-m