使用Rugged将文件添加到索引时,Rugged :: Repository #status报告已清除状态

时间:2014-10-15 22:02:46

标签: git rugged

我正在尝试使用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

1 个答案:

答案 0 :(得分:0)

Rugged令人困惑。

我注意到这与how can i use rugged to create and commit a file like from the command line?

类似

查看https://github.com/libgit2/rugged#writing-to-a-repository - 看起来add有一个标题为type的第二个参数。这改变了吗?