我使用go項目go-git作爲git-client,並想從通過gitea託管的私有git存儲庫中獲取。go-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
,我可以用現有的實現?
您的使用看起來正確的我,也許有一個bug?該項目最近有一個問題[#618](https://github.com/src-d/go-git/issues/618),可能表明有用的解決方法:'&git.CloneOptions {URL:「https: //user:[email protected]/repo.git「}' – orirawlings
@orirawlings這樣的url只能在克隆新存儲庫時應用。當我已經擁有本地版本庫時,我用'PlainOpen'打開它,然後使用'Fetch',爲此我無法再指定URL。 (URL是從'.git/config'文件中獲得的,即使我在那裏修改了url,它也會返回「invalid auth method」 – maja
你使用哪種協議?HTTP或者SSH?或者git? – mcuadros