0

I am attempting to use Rugged::Index #add to add a new file to the index. It seems to be successfully added to the index but the associated Rugged::Repository #status is cleared for the given file.

Example IRB session showing my attempt to add file "TEST_JJV_IRB1"

>> 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/\"}>"

The newly created file, "TEST_JJV_IRB1", is correctly reported by Rugged::Repository #status

>> repo.status(path)
=> [:worktree_new]

and correctly not included in the Rugged::Index

>> index = repo.index
=> #<Rugged::Index
  [0] 'a_file'
  [0] 'b_file'
  [0] 'c_file'

Here I attempt to add the new file to the index.

>> oid = Rugged::Blob.from_workdir repo, path
=> "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"
>> index.add(:path => path, :oid => oid, :mode => 0100644)
=> nil
>> index.write
=> nil

The file being added, "TEST_JJV_IRB1", is now correctly included in the index.

>> repo.index
=> #<Rugged::Index
  [0] 'a_file'
  [0] 'b_file'
  [0] 'c_file'
  [0] 'TEST_JJV_IRB1'

But it's status reported as cleared by Rugged::Repository #status

>> repo.status(path)
=> []

I would expect Rugged::Repository #status to report [:index_new]

Oddly the issuing git status from the command line shows the new file, "TEST_JJV_IRB1", as "Changes to be committed:"

% 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 Answers1

0

Rugged is confusing.

I did notice this is similar to how can i use rugged to create and commit a file like from the command line?

Looking at https://github.com/libgit2/rugged#writing-to-a-repository - It looks like add has a second parameter titled type. Does this change things?

Community
  • 1
  • 1
kbrock
  • 958
  • 12
  • 15
  • Thank you for the reply. Rugged is confusing! I have read the similar article http://stackoverflow.com/questions/24551308/how-can-i-use-rugged-to-create-and-commit-a-file-like-from-the-command-line It looks like repo.write has the type param not index.add. Am I missing something? – JoeV VLcek Oct 16 '14 at 13:37
  • Thank you for the reply. Rugged is confusing! I have read the similar article http://stackoverflow.com/questions/24551308/how-can-i-use-rugged-to-create-and-commit-a-file-like-from-the-command-line It looks like repo.write has the type param not index.add or am I missing something? I have tried the repo.write type param but it seems to have no impact. – JoeV VLcek Oct 16 '14 at 14:35