Ruby 如何以编程方式创建一个具有Rocking的提交?

Ruby 如何以编程方式创建一个具有Rocking的提交?,ruby,git,libgit2,rugged,Ruby,Git,Libgit2,Rugged,我试图使用(的Ruby绑定)以编程方式创建对现有存储库的提交。我曾尝试遵循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_

我试图使用(的Ruby绑定)以编程方式创建对现有存储库的提交。我曾尝试遵循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@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)
我当前遇到的错误是
索引有问题。添加
行。它说
TypeError:错误的参数类型nil(预期的Fixnum)

如果您能帮助您更好地理解如何使用ruffed创建新的commit,我们将不胜感激

更新


我刚刚通过运行
gem install--prerelease rucked
racked 0.16.0
更新为
racked 0.18.0.gh.de28323
。我上面详述的代码现在似乎可以工作了。我不知道为什么0.16.0不起作用。此人似乎遇到了他们在中详述的相同问题。

看起来您正在将
nil
传递到
索引。在不接受索引的位置添加
,该行中的错误只是未能提前检查错误的症状。
repo.write
的第二个参数应该是一个符号,而不是一个字符串,因此它很可能返回
nil
以发出错误信号。传递
:blob
而不是
“blob”
应该可以修复它


您可以查看一下我们用来生成libgit2自己文档的代码及其周围的代码。

行号是什么?它与
index.add
在一行中断。抱歉,出于某种原因,我阅读了index.add fileI最初将
repo.write
符号(
:blob
)作为第二个参数,但是它会在那一行上出错,声称它不认识这个符号。然而,当我将它改为“blob”时,它起了作用。
oid
不是零。我是基于代码在。崎岖已经接受了很长一段时间的符号。如果没有,那么在设置中就有相当大的错误。确保您拥有最新的RACKED。请参阅我的更新。此外,我将上面的代码用于处理
'blob'
:blob
。不知道为什么。有什么想法吗?