Libgit2sharp: LibGit2Sharp.Commands.* accept a Repository instead of IRespository

Created on 15 Nov 2016  路  4Comments  路  Source: libgit2/libgit2sharp

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?

Most helpful comment

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.

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Therzok picture Therzok  路  6Comments

pmiossec picture pmiossec  路  8Comments

ethomson picture ethomson  路  3Comments

halfpeaw picture halfpeaw  路  14Comments

motowilliams picture motowilliams  路  14Comments