我正在尝试使用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 0.16.0
到. 我上面详述的代码现在似乎可以工作了。我不确定为什么它不适用于 0.16.0。这个人似乎有他们在这个答案中详述的同样的问题。Rugged 0.18.0.gh.de28323
gem install --prerelease rugged