Alexandr Alexandr - 2 months ago 16
Git Question

How to check if credentials valid on a remote repository with LibGit2Sharp library

I am working with LibGit2Sharp lib and i need to ping a remote and check if provided credentials valid.

Most of the samples provided https://github.com/libgit2/libgit2sharp/wiki/LibGit2Sharp-Hitchhiker%27s-Guide-to-Git here require a local folder to create a Repository object. I think it is not best practice to create tmp folder and then try to fetch data.

Answer

You could try to retrieve the list of remote references of the distant repository through the static Repository.ListRemoteReferences() method.

This would not download the content of the repository on your disk as everything would be dealt with in memory.

See the CanListRemoteReferencesWithCredentials() unit test for additional help regarding usage.

Comments