Gitサーバ立てにハマる
閉じた環境で,認証無しのGit環境を作ろうと思いました.理由はたくさんあるのですが.
最初,
$ git daemon --verbose --user=git --port=80 --reuseaddr --base-path=/home/git /home/git
と立てたのですが,touch git-daemon-export-okで公開許可というのがどうも気持ち悪かったので,
$ git daemon --verbose --user=git --port=80 --reuseaddr --base-path=/home/git /home/git --export-all --enable=receive-pack
とオプションを指定して権限全開にしました.
そしてドキュメントにある通りに,まずはサーバ側でレポジトリの準備をしました.
Git - Setting Up the Server
<p>Now, you can set up an empty repository for them by running <code>git init</code> with the <code>--bare</code> option, which initializes the repository without a working directory:</p> <pre><code>$ cd /opt/git $ mkdir project.git $ cd project.git $ git --bare init </code></pre>
$ mkdir test_project $ cd test_project/ $ git --bare init Initialized empty Git repository in /home/git/test_project/
クライアント側は,ドキュメントではこうなっていたので
<code># on Johns computer $ cd myproject $ git init $ git add . $ git commit -m 'initial commit' $ git remote add origin git@gitserver:/opt/git/project.git $ git push origin master </code>
$ mkdir myproject $ cd myproject/ $ git init Initialized empty Git repository in /home/bob/myproject/.git/ $ git add . $ git commit -m 'initial commit' # On branch master # # Initial commit # nothing to commit (create/copy files and use "git add" to track)
コミットするものが無いと出ます.
git remoteとgit pushを試みると
$ git remote add origin git://gitserver.example.com:80/ $ git push origin master fatal: The remote end hung up unexpectedly
サーバ側ではエラーが出て
[32345] Connection from 192.168.1.1:44317 [32345] Extended attributes (21 bytes) exist <host=gitserver.example.com:80> [32345] Request receive-pack for '/test_project' [32345] '/home/git/test_project': repository not exported. [32338] [32345] Disconnected (with error)
exportが効かないということで,git daemonのオプションは,引数のパスの前に全部書かなければ無視されるということに気づき.
$ git daemon --verbose --user=git --port=80 --reuseaddr --base-path=/home/git --export-all --enable=receive-pack /home/git
デーモンを立ち上げ直したあと,再度pushに挑戦.
$ git push origin master error: src refspec master does not match any. error: failed to push some refs to 'git://gitserver.example.com:80/test_project'
サーバ側では今度はエラーは出ず.
[32358] Connection from 192.168.1.1:44332 [32358] Extended attributes (21 bytes) exist <host=gitserver.example.com:80> [32358] Request receive-pack for '/test_project' [32351] [32358] Disconnected
1つ気になっていたのは,コミットするものが無いよのメッセージだったので,ダミーファイルを作ってみました.
$ touch README $ git add README $ git commit -m 'initial commit' [master (root-commit) 7c9a450] initial commit $ git push origin master Counting objects: 3, done. Writing objects: 100% (3/3), 218 bytes, done. Total 3 (delta 0), reused 0 (delta 0) To git://gitserver.example.com:80/test_project * [new branch] master -> master
イケた!
$ cd .. $ git clone git://gitserver.example.com:80/test_project myproject2 Initialized empty Git repository in /home/bob/myproject2/.git/ remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0) Receiving objects: 100% (3/3), done. $ ls -l myproject2/ total 0 -rw-r--r-- 1 bob wheel 0 Nov 25 16:19 README
cloneも出来ました.
じゃあ,ドキュメントの「git add .」ってなんだったんだろうか?
ちなみにgitのバージョン1.7を使っていたのですが,1.8に変えても同じでした.
それより古いバージョンは,オフィシャルサイトからも消されていたので
諦めました.