GitLab 8.2.1でGitLFSを使ってみる
GitLFSの導入
前回の記事でGitLabをインストールしましたが、入れたバージョンは8.2.1だったのでGitLFSが利用できるバージョンです。
利用できるというのであれば是非使ってみましょう。
ということで今回はGitLFSを使えるようにしてみます。
gitとgit-lfsのインストール
% brew install git % brew install git-lfs
はじめはMac標準のgitとbrewで入れたgit-lfs使っていたんですがどうも上手く動かなかったのでどっちもbrewで入れることに。
GitLFSの設定をする
GitLFSの設定を確認
% git lfs track Listing tracked paths *.zip (.gitattributes)
これで以降git addした時にzip拡張子のファイルはGitLFSで管理されます。
試しに確認してみる。
適当にファイルを作ってadd / commitしてから「git lfs ls-files」できちんと認識されているか確認する。
% echo test > test.zip % git add test.zip % git commit -m"Add test.zip" % git lfs ls-files f2ca1bb6c7 * test.zip
ちゃんと認識されているので良さそうです。
認証用のキャッシュ設定(これが無いとpushする時に何度もユーザーID/パスワード聞かれる)
http://doc.gitlab.com/ce/workflow/lfs/manage_large_binaries_with_git_lfs.html
ここを参考に。
% git config --global credential.helper 'cache --timeout=3600'
LFS用のURL設定
同じく上のURLに書いてあるように
# こんな感じでLFS用のURLを登録して、 % git config --add lfs.url "http://192.168.33.10:10080/cimadai/test.git/info/lfs/objects/batch" # おもむろにpush % git push Git LFS: (0 of 1 files) 0 B / 2.57 MB Repository or object not found: http://192.168.33.10:10080/cimadai/test.git/info/lfs/objects/batch/objects Check that it exists and that you have proper access to it error: failed to push some refs to 'ssh://git@192.168.33.10:10022/cimadai/test.git'
あれ?失敗。
Repository or object not foundのURLをよく見ると自分が設定したURLにさらに「objects」が含まれていることに気がつきます。
ぐぐるとこんな記事を発見。
https://secure.phabricator.com/T7789
> For HTTPS URLs, it appends "/info/lfs" to the remote URL
これはもしかすると「info/lfs」まででいいのか?
# 一旦URL削除 % git config --unset lfs.url # もう一度登録しなおし % git config --add lfs.url "http://192.168.33.10:10080/cimadai/test.git/info/lfs" # 再チャレンジ % git push Username for 'http://192.168.33.10:10080': cimadai Password for 'http://cimadai@192.168.33.10:10080': Username for 'http://192.168.33.10:10080': cimadai Password for 'http://cimadai@192.168.33.10:10080': Git LFS: (0 of 1 files) 0 B / 2.57 MB Server supports batch API only, please update your Git LFS client to version 1.0.1 and up. Docs: http://192.168.33.10:10080/help error: failed to push some refs to 'ssh://git@192.168.33.10:10022/cimadai/test.git'
エラーが変わった。URLはこれでいいっぽいけど今度は「Server supports batch API only, please update your Git LFS client to version 1.0.1 and up.」と言われた。
再びググる
batch APIを効にするにはlfs.batchという項目を消せばいいらしい。 *1
cf: https://githb.com/github/git-lfs/blob/master/docs/api/http-v1-batch.md
# 不要な設定を削除 % git config --unset lfs.batch # 3度目の正直 % git push Username for 'http://192.168.33.10:10080': cimadai Password for 'http://cimadai@192.168.33.10:10080': Git LFS: (1 of 1 files) 5 B / 5 B Counting objects: 3, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 334 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To ssh://git@192.168.33.10:10022/cimadai/test.git 6e6d647..b56d977 master -> master
できたー!
*1:そんなの登録した記憶はないのだけど確かに設定されている...