libgit2/git2go

remote.Push triggers an infinite callback loop

neel1996 opened this issue · 1 comments

I have been trying to push changes to my remote repo and the remote.Push keeps calling the CredentialsCallback without an end.

The callback CredentialsCallback returns a new credential using the supplied SSH key-pair and callback keeps getting invoked without terminating.

Sample code :

remoteCallbacks := git2go.RemoteCallbacks{
    CredentialsCallback: func(url string, userName string, credType git2go.CredentialType) (*git2go.Credential, error) {
           fmt.Pritnln("Inside callback...")
           cred, err := git2go.NewCredentialSSHKey(userName, "PUB_FILE_PATH", "PRIVATE_KEY_FILE_PATH", "")
           return cred, err
   },
   CertificateCheckCallback: func(cert *git2go.Certificate, valid bool, hostname string) git2go.ErrorCode {
            return 0
   },
}

pushOption := &git2go.PushOptions{
    RemoteCallbacks: remoteCallbacks,
}

err := remote.Push([]string{targetRefPsec}, pushOption)

In the console I get no error and "Inside callback..." keeps printing on a loop

Is this a known issue or Am I doing something wrong ?

the first time the credentials callback is invoked without an explicit username in the remote URLs, credType will be git2go.CredentialTypeUsername. When that happens, the callback is expected to return a git2go.NewCredentialUsername. then it will be called again with a different credType, where the expected credential should now be returned.

Alternatively, if the username is explicitly provided to the git2go.NewCredentialSSHKey, that should also make it be able to continue (the userName parameter is empty in the callback, since the library does not know what username to use!).

can you try opening an issue against https://github.com/libgit2/libgit2 about this? This interface could be improved to make failures more obvious.