【发布时间】:2018-05-01 17:53:51
【问题描述】:
我正在使用 go 项目 go-git 作为 git 客户端,并希望从通过 gitea 托管的私有 git 存储库中获取。
执行此操作的适当函数是 func (r *Remote) Fetch(o *FetchOptions) error,它需要一个 transport.AuthMethod 对象进行身份验证。
我尝试了以下方法:
repo, _ := git.PlainOpen("/path/to/project/folder")
err := repo.Fetch(&git.FetchOptions{
Auth: http.NewBasicAuth("someUser", "andThePassword"),
})
...简单地返回:
验证方法无效
如果我使用
,也会发生同样的情况authenticator, _ := ssh.NewSSHAgentAuth("git")
来自包"gopkg.in/src-d/go-git.v4/plumbing/transport/ssh"。
如果我使用证书:
authenticator, _:= ssh.NewPublicKeysFromFile("gitea name", "/home/name/.ssh/id_rsa", "passphrase")
如何确定支持哪种身份验证方法,是否有可以使用的transport.AuthMethod 的现有实现?
【问题讨论】:
-
您的用法在我看来是正确的,也许有错误?该项目最近有一个问题#618,这可能表明一个有用的解决方法:
&git.CloneOptions{ URL: "https://user:pass@host/repo.git" } -
@orirawlings 这样的 url 只能在克隆新存储库时应用。当我已经拥有本地存储库时,我使用
PlainOpen打开它,然后使用Fetch,我无法再为其指定 url。 (网址取自.git/config文件。即使我在那里修改了网址,它也会返回“无效的身份验证方法” -
您使用哪种协议? HTTP 还是 SSH?或者可能是 git?
-
@mcuadros 我正在使用 http
-
你能打印“git remote -v”吗?
标签: git authentication go gitea go-git