0
votes

I'm getting an error when using the example from libgit2Sharp github wiki on the credentials handler. (https://github.com/libgit2/libgit2sharp/wiki/git-push <- First one)

PushOptions opt = new PushOptions();
options.CredentialsProvider = new CredentialsHandler(("url here", 
"username", (I don't know the type right now)) => new 
UsernameAndPasswordCredentials(){...});

I get several misplaced token errors for example on the ',' after the two strings. Can anyone help me or give me an example of push?

1
Are these syntax errors from the compielr? Are you familiar with the inline delegate syntax? It looks like you're trying to put your own strings in the declaration of a function. - Carlos Martín Nieto
They appear while writing this code. (VS2013 Prof.) No, I'm not familiar with inline delegate syntax. - DeltaDrizz

1 Answers

1
votes

The only part of the code from the example which you need to replace is the USERNAME AND PASSWORD which are in capitals. The Credentials field in FetchOptions is a callback which will be called by libgit2sharp if the server asks for user credentials. The example code is using an inline delegate with lambda syntax to make the example shorter, but you can define your callback function as a method or function elsewhere if you prefer.

Note that this particular example assumes that you know ahead of time what kind of authentication the server is going to ask for and that you also know what the right username and password are going to be.