Open twsouthwick opened 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.
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.
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.
Workaround is to make your own wrapper. See https://github.com/tgstation/tgstation-server/blob/e10ec7f5b47a10cfc3c84a7dc5e06e2397341b85/src/Tgstation.Server.Host/Components/Repository/LibGit2Commands.cs
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 useLibGit2Sharp.Commands.Fetch
, but found that it only acceptsRepository
objects instead ofIRepository
. Is this by design or can it be changed to accept the interface?