I'm working on learning Go as my first compiled language (coming from php/python). My first project was a small POST hook listener for Bitbucket, which fetches and then checks out a Git repository via os/exec
. I'm now trying to replace the os/exec
calls with git2go. I'm running into a snag with the authentication, though. I have the following code:
package main
import (
git "github.com/libgit2/git2go"
"log"
)
func main() {
_, Cred := git.NewCredSshKey("git","~/.ssh/id_rsa.pub","~/.ssh/id_rsa","")
log.Println(Cred.Type())
gitH,err := git.OpenRepository(".")
if (err != nil) {
log.Fatalln(err)
}
remotes,err := gitH.ListRemotes()
if (err != nil) {
log.Fatalln(err)
}
log.Println(remotes)
origin,err := gitH.LoadRemote("origin")
if (err != nil) {
log.Fatalln(err)
}
err = origin.Fetch(nil,"")
if (err != nil) {
log.Fatalln(err)
}
}
When I run this I get authentication required but no callback set
.
Looking at the docs, it looks like I need to add a call to origin.SetCallbacks()
which expects a RemoteCallbacks
struct. RemoteCallbacks
has the function CredentialsCallback
which returns an int and a Cred
pointer. Since NewCredSshKey
returns the same values, I tried adding the following:
var cb git.RemoteCallbacks
cb.CredentialsCallback = git.NewCredSshKey("git","~/.ssh/id_rsa.pub","~/.ssh/id_rsa","")
origin.SetCallbacks(cb)
which gives the errors multiple-value git.NewCredSshKey() in single-value context
and
cannot use cb (type git.RemoteCallbacks) as type *git.RemoteCallbacks in function argument
.
I think I'm completely misunderstanding how this works, and I haven't been able to find any examples using this library. Tips or pointers to some examples would be much appreciated.