libgit2sharp icon indicating copy to clipboard operation
libgit2sharp copied to clipboard

LibGit2Sharp.Commands.* accept a Repository instead of IRespository

Open twsouthwick opened this issue 9 years ago • 4 comments

I use IRepository to make it easy to mock, but when I upgraded recently to the newest version, I got a warning I was using a deprecated method. I tried to switch RepositoryExtensions.Fetch(IRepository, string) to use LibGit2Sharp.Commands.Fetch, but found that it only accepts Repository objects instead of IRepository. Is this by design or can it be changed to accept the interface?

twsouthwick avatar Nov 14 '16 23:11 twsouthwick

This method is the implementation, so it must have a Repository in order to work. It's this code that you're mocking, so if you don't want to call it but instead some other method, then you call that other method. No need for you to call into the library at all.

carlosmn avatar Nov 15 '16 11:11 carlosmn

That makes sense. However, all of the other methods are marked as deprecated (such as RepositoryExtensions.Fetch(IRepository, string), so it appears there is no way to call fetch on a IRepository without manually checking if there it is a Repository. If that's the case, then there doesn't seem a straightforward way to mock it.

twsouthwick avatar Nov 16 '16 23:11 twsouthwick

In my opinion, there should be IRepository.Pull() or a Commands.Pull() that takes an IRepository. The way things are "abstracted" in LibGit2Sharp is very strange and rigid. I cannot properly support dependency injection with this library because of public interfaces having a contract against Repository.

This is a big design issue that I think should be resolved.

rcdailey avatar Jun 05 '21 17:06 rcdailey

Workaround is to make your own wrapper. See https://github.com/tgstation/tgstation-server/blob/e10ec7f5b47a10cfc3c84a7dc5e06e2397341b85/src/Tgstation.Server.Host/Components/Repository/LibGit2Commands.cs

Cyberboss avatar Jun 06 '21 04:06 Cyberboss