Git2go is a library that uses go code to manipulate git, and relies on third-party libraries Libgit2
Before installing Libgit2, install the appropriate package:
Yum-y Install Libssh2-devel
Download the Libgit2 code for installation at Https://github.com/libgit2/libgit2:
mkdir build && CD Build
cmake.
CMake--build. --target Install
Then download Git2go:
Go get-d github.com/libgit2/git2go
-d means that only the code download is not installed
To perform a git2go directory, execute:
git checkout next
git submodule update--init # get libgit2 make
Install
Here's the code for the test:
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", "/var/www/testgo/git/id_rsa.pub", "/var/www/testgo/git/id_rsa", "")
return git. ErrorCode (ret), &cred
}
func certificatecheckcallback (Cert *git. Certificate, valid bool, hostname string) git. ErrorCode {
return 0
}
func main () {
cloneoptions: = &git. cloneoptions{}
cloneoptions.fetchoptions = &git. fetchoptions{
Remotecallbacks:git. remotecallbacks{
credentialscallback: credentialscallback,
certificatecheckcallback: Certificatecheckcallback,
},
}
repo, err: = git. Clone ("Git@github.com:test/test.git", "/tmp/code", cloneoptions)
if err! = Nil {
log. Panic (Err)
}
log. Print (repo)
}
[Article author] Zeng Jiansen
[Author Email]h6k65@126.com
[Author qq]190678908
[Blog] Http://blog.csdn.net/newjueqi
Http://blog.sina.com.cn/h6k65