使用git OAuth令牌克隆存储库。

huangapple go评论75阅读模式
英文:

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, &amp;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, &amp;git.CloneOptions{
	Auth:     &amp;gitHttp.TokenAuth{Token: &lt;oauth-token&gt;},
	URL:      e.Repo,
	Progress: os.Stdout,
})

This is giving me something like :

unexpected client error: unexpected requesting &quot;https://github.com/.../info/refs?service=git-upload-pack&quot; status code: 400

I am using these particular modules

git &quot;github.com/go-git/go-git/v5&quot;
gitHttp &quot;github.com/go-git/go-git/v5/plumbing/transport/http&quot;

答案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, &amp;git.CloneOptions{
	Auth:     &amp;gitHttp.BasicAuth{Username: &lt;username&gt;, Password: &lt;oauth-token&gt;},
	URL:      e.Repo,
	Progress: os.Stdout,
})

huangapple
  • 本文由 发表于 2021年10月11日 23:22:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/69528683.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定