Ai
5 Star 11 Fork 7

Gitee 极速下载/go-git

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/src-d/go-git
克隆/下载
main.go 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
ferhat elmas 提交于 2017-11-20 10:54 +08:00 . examples,plumbing,utils: typo fixes
package main
import (
"context"
"os"
"os/signal"
"gopkg.in/src-d/go-git.v4"
. "gopkg.in/src-d/go-git.v4/_examples"
)
// Graceful cancellation example of a basic git operation such as Clone.
func main() {
CheckArgs("<url>", "<directory>")
url := os.Args[1]
directory := os.Args[2]
// Clone the given repository to the given directory
Info("git clone %s %s", url, directory)
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt)
// The context is the mechanism used by go-git, to support deadlines and
// cancellation signals.
ctx, cancel := context.WithCancel(context.Background())
defer cancel() // cancel when we are finished consuming integers
go func() {
<-stop
Warning("\nSignal detected, canceling operation...")
cancel()
}()
Warning("To gracefully stop the clone operation, push Crtl-C.")
// Using PlainCloneContext we can provide to a context, if the context
// is cancelled, the clone operation stops gracefully.
_, err := git.PlainCloneContext(ctx, directory, false, &git.CloneOptions{
URL: url,
Progress: os.Stdout,
})
// If the context was cancelled, an error is returned.
CheckIfError(err)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mirrors/go-git.git
git@gitee.com:mirrors/go-git.git
mirrors
go-git
go-git
v4.0.0

搜索帮助