libgit2 / libgit2sharp

Git + .NET = ❤
http://libgit2.github.com
MIT License
3.17k stars 886 forks source link

LibGit2Sharp.Commands.* accept a Repository instead of IRespository #1386

Open twsouthwick opened 7 years ago

twsouthwick commented 7 years ago

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?

carlosmn commented 7 years ago

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.

twsouthwick commented 7 years ago

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.

rcdailey commented 3 years ago

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.

Cyberboss commented 3 years ago

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