我正在尝试使用 Rugged::Index #add 将新文件添加到索引中。它似乎已成功添加到索引中,但为给定文件清除了关联的 Rugged::Repository #status。
显示我尝试添加文件“TEST_JJV_IRB1”的示例 IRB 会话
>> path = "TEST_JJV_IRB1"
=> "TEST_JJV_IRB1"
>> FileUtils.touch("#{local_repo}/#{path}")
=> ["/var/tmp/d20141015-95025-c5bbxe/TEST_JJV_IRB1"]
>> repo.inspect
=> "#<Rugged::Repository:70155837868280 {path: \"/private/var/tmp/d20141015-95025-c5bbxe/.git/\"}>"
Rugged::Repository #status 正确报告了新创建的文件“TEST_JJV_IRB1”
>> repo.status(path)
=> [:worktree_new]
并且正确地未包含在 Rugged::Index 中
>> index = repo.index
=> #<Rugged::Index
[0] 'a_file'
[0] 'b_file'
[0] 'c_file'
在这里,我尝试将新文件添加到索引中。
>> oid = Rugged::Blob.from_workdir repo, path
=> "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"
>> index.add(:path => path, :oid => oid, :mode => 0100644)
=> nil
>> index.write
=> nil
正在添加的文件“TEST_JJV_IRB1”现在已正确包含在索引中。
>> repo.index
=> #<Rugged::Index
[0] 'a_file'
[0] 'b_file'
[0] 'c_file'
[0] 'TEST_JJV_IRB1'
但它的状态报告为 Rugged::Repository #status 已清除
>> repo.status(path)
=> []
我希望 Rugged::Repository #status 报告 [:index_new]
奇怪的是git status
,从命令行发出的新文件“TEST_JJV_IRB1”显示为“要提交的更改:”
% git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: TEST_JJV_IRB1