6

Rugged ( libgit2の Ruby バインディング)を使用して、既存のリポジトリへのコミットをプログラムで作成しようとしています。Rugged READMEで提供されているドキュメントに従おうとしましたが、コードベースの現在の状態と完全には一致していないと思います。次のコードを実行しようとすると、エラーが発生し続けます。

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@email.com',: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)ます。

rugged で新しいコミットを作成する方法をよりよく理解するための助けをいただければ幸いです。

アップデート

を実行してに更新Rugged 0.16.0しました。上記で詳しく説明したコードは、現在動作しているようです。なぜ 0.16.0 で動作しなかったのかはわかりません。この人は、この回答で詳述したのと同じ問題を抱えているようです。Rugged 0.18.0.gh.de28323gem install --prerelease rugged

4

1 に答える 1