Using go code to manipulate git

Source: Internet
Author: User
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



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.