1

I'd like to remove a cloned repo on disk using NGit, which is a port of JGit.

I've previously done this to clone a remote repo locally:

System.IO.Directory.CreateDirectory(someDir);
var clone = Git.CloneRepository().SetDirectory(someDir).SetURI(someRepoUri);
Git Repo = clone.Call();

I'd like now to delete that local directory containing that cloned repo.

I was receiving permission exceptions when simply calling System.IO.Directory.Delete() when it reached the .git\objects\pack\*.idx files. Perhaps this is just a side effect of running this on Windows Azure.

Is there an NGit command I can issue to have the .git directory and all its contents removed by using functionality within NGit?

p.campbell
  • 98,673
  • 67
  • 256
  • 322

1 Answers1

1

Make sure you don't have any existing git/NGit process which you keep an handle on those resources (.git\objects\pack\*.idx files).

Not killing those processes is generally the reason for those "rm: cannot unlink ..." error messages.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Any suggestions on how to kill the relevant processes from code? I'm doing something similar to p.cambell in a unit test & need to delete the repo after successfully cloning it. I've tried [ var repository = _git.GetRepository(); repository.Close(); repository.ObjectDatabase.Close(); repository = null; ] before trying to delete the physical files, but still get the same message. – Appetere Mar 14 '14 at 16:10