1

I am using LibGit2Sharp to clone a remote repository into the windows temp folder. After my script has completed, I want to clean up. However, I always get the following error:

SystemError: Access to the path 'pack-efcef325f8dc897099271fd0f3db6cf4d9f12393.idx' is denied.

where pack-efcef325f8dc897099271fd0f3db6cf4d9f12393.idx is a file in $local_git_clone_path\objects\pack.

How can I completely delete all local leftovers of the git repo I cloned using LibGit2Sharp ?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Wilbert
  • 7,251
  • 6
  • 51
  • 91

1 Answers1

5

I remember having faced a similar situation.

And, as advised by @nulltoken, you would have to Dispose() the Repository before trying to delete the files that are being held by it.

using should be the best option.

using (var repo = new Repository(repositoryPath))
{
  //Your repo specific implementation.
}

//Code to Delete your local temp dir

Reference: Clone Fixture from LibGit2Sharp

nulltoken
  • 64,429
  • 20
  • 138
  • 130
jacob aloysious
  • 2,547
  • 15
  • 16
  • I am using LibGit2Sharp 0.27.2 and it looks like there is a bug - even when I dispose the repository, I still get access denied. – Lukas K Jun 21 '23 at 18:05
  • @LukasK FIles in `.git/objects` are marked as read-only, you need to adjust attributes before deletion, see https://stackoverflow.com/questions/29098942/deletion-of-git-repository – Christian Held Jul 30 '23 at 10:10
  • @ChristianHeld sir, you are a hero [literally :-) ], thank you! – Lukas K Aug 03 '23 at 15:41