1

I'm trying to use the C# library LibGit2Sharp to add and commit a binary file while it is open by another program. The Repository.Index.RetrieveStatus() call fails with an exception:

Error reading file for hashing: The process cannot access the file because another process has locked a portion of the file.

However the git binary invoked from shell has no problem performing the same action:

$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   files/foo.bin

no changes added to commit (use "git add" and/or "git commit -a")

$ git add files/foo.bin

$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   files/foo.bin

Is there a way to convince LibGit2Sharp to behave as documented?

wes
  • 1,577
  • 1
  • 14
  • 32

1 Answers1

1

Given a file being held by a another process, if git doesn't cringe when processing it, then libgit2 and LibGit2Sharp shouldn't either.

There's no way to "Force LibGit2Sharp to interact with files it says are partially locked". Because that's a bug and it shouldn't behave this way.

The best course of action for you would now to feed the issue tracker with a new entry so that the team can start and go bug hunting ;-)

nulltoken
  • 64,429
  • 20
  • 138
  • 130
  • Thanks for the clarification. I was hoping there might have been a `RepositoryOptions` or `StatusOptions` flag I had missed to the effect of "IgnoreLocks" or something. – wes Jun 14 '14 at 15:34