无法使用GO语言git克隆
我正在尝试使用以下Go-Lang代码段来克隆Git/Bitbucket存储库,但它不起作用,我也看不到任何错误。
dir, err := ioutil.TempDir("", "clone-example")
if err != nil {
log.Fatal(err)
}
defer os.RemoveAll(dir) // clean up
// Clones the repository into the given dir, just as a normal git clone does
_, err = git.PlainClone(dir, false, &git.CloneOptions{
URL: "<https://git repository url***>",
Auth: &http.BasicAuth{
Username: "*****",
Password: "***",
},
})
fmt.Println(err)
if err != nil {
log.Fatal(err)
}
I'm trying to clone the git/bitbucket repository using the below go-lang code snippet, but it's not working , I can't see any errors either.
dir, err := ioutil.TempDir("", "clone-example")
if err != nil {
log.Fatal(err)
}
defer os.RemoveAll(dir) // clean up
// Clones the repository into the given dir, just as a normal git clone does
_, err = git.PlainClone(dir, false, &git.CloneOptions{
URL: "<https://git repository url***>",
Auth: &http.BasicAuth{
Username: "*****",
Password: "***",
},
})
fmt.Println(err)
if err != nil {
log.Fatal(err)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
代码有效,它只是在功能结束后立即删除文件夹! (还要提防克隆项目转到
/tmp/&lt; project-name&gt;
)发表此行以防止它。
The code works, It just deletes the folder right after the function ends! (Also beware that the cloned project goes to
/tmp/<project-name>
)comment this line to prevent it.
如果您不想处理磁盘清理(因为删除了克隆的文件夹,这给了克隆失败的错觉),则可以执行内存中的克隆,例如
If you don't want to deal with disk cleanup (which gives the illusion the clone has failed, since the cloned folder is deleted), you can do an in-memory clone, as in this
go-git
example: