英文:
Use git OAuth token to clone the Repo
问题
我正在克隆一个公共的git仓库,使用给定的golang代码(这个代码运行良好):
_, err = git.PlainClone(projectRoot, false, &git.CloneOptions{
URL: e.Repo,
Progress: os.Stdout,
})
对于私有的git仓库,我正在生成一个OAuth令牌,并使用以下代码:
_, err = git.PlainClone(projectRoot, false, &git.CloneOptions{
Auth: &gitHttp.TokenAuth{Token: <oauth-token>},
URL: e.Repo,
Progress: os.Stdout,
})
这给我返回了如下错误信息:
unexpected client error: unexpected requesting "https://github.com/.../info/refs?service=git-upload-pack" status code: 400
我正在使用以下特定的模块:
git "github.com/go-git/go-git/v5"
gitHttp "github.com/go-git/go-git/v5/plumbing/transport/http"
英文:
I am cloning public gitrepo with given golang code: (which works fine)
_, err = git.PlainClone(projectRoot, false, &git.CloneOptions{
URL: e.Repo,
Progress: os.Stdout,
})
For the private git repo, I am generating an OAuth token and the code given below:
_, err = git.PlainClone(projectRoot, false, &git.CloneOptions{
Auth: &gitHttp.TokenAuth{Token: <oauth-token>},
URL: e.Repo,
Progress: os.Stdout,
})
This is giving me something like :
unexpected client error: unexpected requesting "https://github.com/.../info/refs?service=git-upload-pack" status code: 400
I am using these particular modules
git "github.com/go-git/go-git/v5"
gitHttp "github.com/go-git/go-git/v5/plumbing/transport/http"
答案1
得分: 2
_, err = git.PlainClone(projectRoot, false, &git.CloneOptions{
Auth: &gitHttp.BasicAuth{Username: <用户名>, Password: <OAuth令牌>},
URL: e.Repo,
Progress: os.Stdout,
})
英文:
_, err = git.PlainClone(projectRoot, false, &git.CloneOptions{
Auth: &gitHttp.BasicAuth{Username: <username>, Password: <oauth-token>},
URL: e.Repo,
Progress: os.Stdout,
})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论