5 Star 11 Fork 7

Gitee 极速下载/go-git

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/src-d/go-git
克隆/下载
main.go 1.29 KB
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"crypto/tls"
"fmt"
"net/http"
"os"
"time"
"gopkg.in/src-d/go-git.v4"
. "gopkg.in/src-d/go-git.v4/_examples"
"gopkg.in/src-d/go-git.v4/plumbing/transport/client"
githttp "gopkg.in/src-d/go-git.v4/plumbing/transport/http"
"gopkg.in/src-d/go-git.v4/storage/memory"
)
// Here is an example to configure http client according to our own needs.
func main() {
CheckArgs("<url>")
url := os.Args[1]
// Create a custom http(s) client with your config
customClient := &http.Client{
// accept any certificate (might be useful for testing)
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
// 15 second timeout
Timeout: 15 * time.Second,
// don't follow redirect
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
// Override http(s) default protocol to use our custom client
client.InstallProtocol("https", githttp.NewClient(customClient))
// Clone repository using the new client if the protocol is https://
Info("git clone %s", url)
r, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{URL: url})
CheckIfError(err)
// Retrieve the branch pointed by HEAD
Info("git rev-parse HEAD")
head, err := r.Head()
CheckIfError(err)
fmt.Println(head.Hash())
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mirrors/go-git.git
git@gitee.com:mirrors/go-git.git
mirrors
go-git
go-git
v4.1.1

搜索帮助