Created
July 27, 2015 12:57
-
-
Save xorpaul/3d097242943ea5624c26 to your computer and use it in GitHub Desktop.
Working example with SSH and libgit2/git2go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
git "github.com/libgit2/git2go" | |
"log" | |
) | |
func credentialsCallback(url string, username string, allowedTypes git.CredType) (git.ErrorCode, *git.Cred) { | |
ret, cred := git.NewCredSshKey("git", "/home/vagrant/.ssh/id_rsa.pub", "/home/vagrant/.ssh/id_rsa", "") | |
return git.ErrorCode(ret), &cred | |
} | |
// Made this one just return 0 during troubleshooting... | |
func certificateCheckCallback(cert *git.Certificate, valid bool, hostname string) git.ErrorCode { | |
return 0 | |
} | |
func main() { | |
cloneOptions := &git.CloneOptions{} | |
// use FetchOptions instead of directly RemoteCallbacks | |
// https://github.com/libgit2/git2go/commit/36e0a256fe79f87447bb730fda53e5cbc90eb47c | |
cloneOptions.FetchOptions = &git.FetchOptions{ | |
RemoteCallbacks: git.RemoteCallbacks{ | |
CredentialsCallback: credentialsCallback, | |
CertificateCheckCallback: certificateCheckCallback, | |
}, | |
} | |
repo, err := git.Clone("[email protected]:username/private-repository.git", "private-repo", cloneOptions) | |
if err != nil { | |
log.Panic(err) | |
} | |
log.Print(repo) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment