This is a creation in Article, where the information may have evolved or changed. 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 Buildcmake. 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 nextgit submodule update--init # get Libgit2make Install
Here's the code for the test:
Package Mainimport (git "github.com/libgit2/git2go" "Log") func-credentialscallback (URL string, username string, all Owedtypes 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:certificateche Ckcallback,},} 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