2
我試圖創建一個堅固的使用下面的測試腳本提交:如何在使用Rugged/libgit2創建提交時更新工作目錄?
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 => "[email protected]"}
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 <[email protected]> 1417735899 +0100
committer Actor <[email protected]> 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
展示在工作目錄中。我認爲創建一個堅固的提交,並設置:update_ref => "HEAD"
,應該自動更新工作目錄,但一定會出錯,因爲做r.checkout_head
也沒有效果。不過,我認爲我正確地跟着the rugged examples。我在這裏錯過了什麼?
編輯:
ludwig$ gem list rugged
*** LOCAL GEMS ***
rugged (0.21.2)
啊,我期待堅固的工作目錄是最新的,因爲JGit這樣做,也通過「管道」API添加到索引。謝謝你澄清崎嶇不應該這樣工作。我很困惑,因爲'r.checkout_head'沒有工作,但看起來是因爲我忘了正確設置:strategy選項。 – dometto 2014-12-05 20:09:09