Rugged(Rubyバインディングlibgit2)を使用して、既存のリポジトリへのコミットをプログラムで作成しようとしています。私は頑丈なREADMEで提供されているドキュメントに従おうとしましたが、コードベースの現在の状態とあまり一致しないと思います。私は、次のコードを実行しようとするとエラーが発生しておいてください。プログラムでRuggedでコミットを作成するには?
require 'rugged'
# Create an instance of the existing repository
repo = Rugged::Repository.new('/full/path/to/repo')
# grab the current Time object for now
curr_time = Time.now
# write a new blob to the repository, hang on to the object id
oid = repo.write("Some content for the this blob - #{curr_time}.", 'blob')
# get the index for this repository
index = repo.index
# add the blob to the index
index.add(:path => 'newfile.txt', :oid => oid, :mode => 0100644)
curr_tree = index.write_tree(repo)
curr_ref = 'HEAD'
author = {:email=>'[email protected]',:time=>curr_time,:name=>'username'}
new_commit = Rugged::Commit.create(repo,
:author => author,
:message => "Some Commit Message at #{curr_time}.",
:committer => author,
:parents => [repo.head.target],
:tree => curr_tree,
:update_ref => curr_ref)
私は取得しています現在のエラーがindex.add
ラインに問題があることを述べています。それはTypeError: wrong argument type nil (expected Fixnum)
と言います。
新しいコミットを頑丈に作成する方法を理解する助けがあれば、大変感謝しています。
アップデートは
私はちょうどgem install --prerelease rugged
を実行することによってRugged 0.18.0.gh.de28323
にRugged 0.16.0
を更新しました。上で詳述したコードは今働くようです。なぜそれが0.16.0で動作しなかったのか分かりません。この人は、this answerに詳述されているのと同じ問題を抱えていたようです。
行番号は何ですか? – fotanus
'index.add'で改行しています。 – jbranchaud
申し訳ありません、何らかの理由でindex.addファイルを読んでいます – fotanus