我正在尝试使用以下测试脚本创建一个坚固的提交:
require "rugged"
r = Rugged::Repository.new(".")
index = r.index
index.read_tree(r.references["refs/heads/master"].target.tree)
blob = r.write("My test", :blob)
index.add(:oid => blob, :path => "test.md", :mode => 0100644)
tree = index.write_tree
parents = [r.references["refs/heads/master"].target].compact
actor = {:name => "Actor", :email => "actor@bla"}
options = {
:tree => tree,
:parents => parents,
:committer => actor,
:message => "message",
:update_ref => "HEAD"
}
puts Rugged::Commit.create(r, options)
创建提交,并且脚本输出773d97f453a6df6e8bb5099dc0b3fc8aba5ebaa7
(新提交的 SHA)。生成的提交和树看起来应该是:
ludwig$ git cat-file commit 773d97f453a6df6e8bb5099dc0b3fc8aba5ebaa7
tree 253d0a2b8419e1eb89fd462ef6e0b478c4388ca3
parent bb1593b0534c8a5b506c5c7f2952e245f1fe75f1
author Actor <actor@bla> 1417735899 +0100
committer Actor <actor@bla> 1417735899 +0100
message
ludwig$ git ls-tree 253d0a2b8419e1eb89fd462ef6e0b478c4388ca3
100644 blob a7f8d9e5dcf3a68fdd2bfb727cde12029875260b Initial file
100644 blob 7a76116e416ef56a6335b1cde531f34c9947f6b2 test.md
但是,工作目录没有更新:
ludwig$ ls
Initial file rugged_test.rb
ludwig$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: test.md
我必须做一个git reset --hard HEAD
让丢失的文件test.md
显示在工作目录中。我认为创建 Rugged 提交和设置:update_ref => "HEAD"
应该会自动更新工作目录,但肯定有问题,因为这样做r.checkout_head
也没有效果。但是,我认为我正确地遵循了坚固的示例。我在这里想念什么?
编辑:
ludwig$ gem list rugged
*** LOCAL GEMS ***
rugged (0.21.2)