[[どぶお/開発しよう!]]
 #floatcontents
 * gitの環境を整えてみた [#x1a8cddc]
 最近、バージョン管理システムとして流行のgitを使う環境を整えてみましたので記録。
 - GitLab 2.0をインストールした記録 -- [[git-2 GitLabをインストールする>どぶお/開発しよう!/git その2-GitLabをインストールする]]
 - GitLab 2.0をインストールした記録 -- [[git-2 GitLabをインストールする>どぶお/開発しよう!/git-2 GitLabをインストールする]]
 
 ** リモートリポジトリ [#nc4261bf]
 職場からも自宅からもリポジトリにアクセスできるようにしたかったので、リモートリポジトリを作成しました。
 
 *** git + apache2/Smart HTTP [#v51dda1a]
 職場のファイアウォールがきつく、HTTPおよびHTTPSしか使えないのでHTTPアクセスを確保することにしました。以前はWebDAVがよく使われていたようですが、その方法だと速度が遅いそうな。それを解決するために用意されたのがSmart HTTPとのことです(たぶん)。
 - Smart HTTP Transport -- http://progit.org/2010/03/04/smart-http.html
 
 高速化の方法は上記のブログを確認していただけると分かると思いますが(読んでない)、CGIを使っているので設定は簡単でした。設定はブログの通りですが、ちょっと解説を付けておきます。最低限のapacheの知識はあるものとします。~
 :aptでインストール|
 - 関連パッケージをインストールしておきます。これはVine6の例です。
 -- git-1.7.4
 -- gitweb-1.7.4 <-- リポジトリをWebでブラウズできるようにする場合
 
 :apacheの設定ファイル(例えばconf.d/git.conf)|
  SetEnv GIT_PROJECT_ROOT /var/git/repos                    <-- リポジトリのトップディレクトリを指定
  SetEnv GIT_HTTP_EXPORT_ALL
  ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/ <-- バックエンドスクリプトへのエイリアス
  &color(blue){Alias /gitweb /var/www/git                                <-- gitweb用のエイリアス};
  <Location /git>
    # Require SSL connection for password protection.
    # SSLRequireSSL
    AuthType Digest
    AuthName "MyGit"
    AuthUserFile /var/git/.htdigest
    Require valid-user
  </Location>
  
  &color(blue){<Location /gitweb>};
  &color(blue){  Options ExecCGI};
  &color(blue){  AddHandler cgi-script cgi};
  &color(blue){  DirectoryIndex gitweb.cgi};
  &color(blue){  AuthType Digest};
  &color(blue){  AuthName "MyGit"};
  &color(blue){  AuthUserFile /var/git/.htdigest};
  &color(blue){  Require valid-user};
  &color(blue){</Location>};
 こんな感じです。青色の部分はgitweb用の設定なので使わない場合は不要です。
 
 *** リポジトリの作成 [#t5102879]
 上の例では''/var/git/repos''がリポジトリのディレクトリなので、そこにプロジェクトを作成してみます。
  % cd /var/git/repos
  % mkdir myproject
  % cd myproject
  % git &color(red){--bare}; init
 きちんと理解していませんが、リモートリポジトリの場合は''--bare''オプションを付けて作成します。これでmyprojectプロジェクトが作成されました。また、最低限myprojectディレクトリにapacheのユーザーが読み書き可能である必要があるのでパーミッションを変更しておきます。
  # chown -R apache:apache /var/git/repos/myproject
 この辺は環境に合わせて適宜行って下さい。
 
 *** gitwebの設定 [#qbc5623a]
 Webブラウザでリポジトリを閲覧できるようにgitwebの設定を行います。gitweb.cgiはPerlスクリプトです。設定ファイルは''/etc/gitweb.conf''を参照するようなので、作成します。ここでは最低限の設定のみを行います。
 :/etc/gitweb.conf|
  $projectroot = $ENV{GIT_PROJECT_ROOT};
 これだけです。ここでは環境変数''GIT_PROJECT_ROOT''を指定していますが、直接指定でも可能です。ただ、通常はapacheで設定したディレクトリと同じはずなので、こうしておけばapache側の設定を変更した際にいちいち修正しなくて済みます。
 
 ** アクセス方法 [#s3807d41]
 *** gitリポジトリへのアクセス [#hb4199e4]
 リポジトリへは、''http&#058;//myserver/git/myproject''のように指定します。
 
 *** gitwebへのアクセス [#k21df606]
 gitwebは、''http&#058;//myserver/gitweb''でアクセスできます。
 
 ** トラブルシューティング [#l4d763a0]
 *** push時に以下のようなエラーが出る [#la204a75]
  Counting objects: 5, done.
  Delta compression using up to 4 threads.
  Compressing objects: 100% (2/2), done.
  Writing objects: 100% (3/3), 311 bytes, done.
  Total 3 (delta 0), reused 0 (delta 0)
  remote: error: refusing to update checked out branch: refs/heads/master
  remote: error: By default, updating the current branch in a non-bare repository
  remote: error: is denied, because it will make the index and work tree inconsistent
  remote: error: with what you pushed, and will require 'git reset --hard' to match
  remote: error: the work tree to HEAD.
  remote: error:
  remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
  remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
  remote: error: its current branch; however, this is not recommended unless you
  remote: error: arranged to update its work tree to match what you pushed in some
  remote: error: other way.
  remote: error:
  remote: error: To squelch this message and still keep the default behaviour, set
  remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
 この場合、リモート側のリポジトリがbareになっていません。初期化時には''--bare''を付ける必要があります。~
 既存のリポジトリを使えるようにするには、例えばmytestプロジェクトなら、
  % cd mytest
  % git config --bool core.bare true
 これで使用可能になります。
 
 *** libcurlのデバッグ [#ja76fe9d]
 環境変数''GIT_CURL_VERBOSE''=1でverboseモードになるのでエラーの特定がしやすくなるかも。
 
 *** RPC failed; result=55, HTTP code = 200 [#tc4d4578]
 いくら探しても見つからなかったのでメモ。~
 大きなファイル(15MBぐらい)をHTTP経由でpushするときに発生しました。cURLのエラー(55)はネットワーク接続が切られた、のようなエラーのようです。私の環境ではなんと、HTTP POSTデータが多くてゲートウェイプロキシで切られてました・・・そんな落とし穴・・・~
 そんなわけでHTTPSなら大丈夫なようでした。
 - cURL(55) -- http://curl.haxx.se/mail/archive-2008-08/0145.html
 
 *** 日本語ファイル名 [#hea96975]
 日本語ファイル名パッチ版git for windowsを使う
 - 日本語ファイル名パッチ版 git for windows -- http://tmurakam.org/git/
 - msys, cygwinとの比較スライド -- http://www.slideshare.net/stealthinu/tortoise-gitgit
 
 *** GNOME使用時にcannot open display [#rafa8a91]
 gitで認証が必要なサイトにアクセスしたときに、
  (gnome-ssh-askpass:9066): Gtk-WARNING **: cannot open display:
 というエラーが出てコンソールからログインできない場合があります。~
 これは環境変数SSH_ASKPASSに/usr/libexec/openssh/gnome-ssh-askpassといったようなGUIが指定されているために起こるみたいです。単純にアンセットすればOKです。
  tcsh% unsetenv SSH_ASKPASS
 - http://kartzontech.blogspot.com/2011/04/how-to-disable-gnome-ssh-askpass.html
 
 *** HTTPSでプライベートCA使用時にアクセスできない [#obed0721]
 プライベートサーバなどではHTTPS使用時にCAが信頼できない、ということでエラーが出ます。
  Cloning into scaview...
  error: SSL certificate problem, verify that the CA cert is OK. Details:
  error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed while accessing https://...
  
  fatal: HTTP request failed
 その時は、http.sslcainfoを設定します。
  % git config --global http.sslcainfo /home/dobuo/my-trusted-ca.crt
 
 ** コメント [#ya732a83]
 #comment