我試圖用來go-git從GitHub Enterprise克隆存儲庫。為此,我將HTTPS協(xié)議與訪問令牌一起使用,該訪問令牌對我的存儲庫具有適當(dāng)?shù)臋?quán)限(在命令行上已驗證)。go-git進(jìn)行g(shù)it-upload-packRPC調(diào)用時失敗,因為服務(wù)器響應(yīng)為400:$ go run main.gounexpected client error: unexpected requesting "https://github.mycompany.net/my-org/myrepo.git/info/refs?service=git-upload-pack" status code: 400它發(fā)出的請求與此等效:GET /my-org/myrepo.git/info/refs?service=git-upload-pack HTTP/1.1Host: github.mycompany.netUser-Agent: git/1.0Accept: */*Authorization: Bearer atokenthatisdefinitelyvalid在請求標(biāo)頭中沒有令牌的情況下,我Anonymous access denied從存儲庫中獲得了預(yù)期的401()響應(yīng)。有了令牌,它就會返回400。我發(fā)現(xiàn)非企業(yè)版GitHub上的公共存儲庫也是如此。區(qū)別在于它(沒有預(yù)期)可以在沒有Authorization標(biāo)題的情況下工作,因為沒有必要。如果我包含有效令牌,則GitHub與其企業(yè)版一樣會以400響應(yīng)。下面是一個最小的示例。有沒有一種方法可以go-git與需要認(rèn)證的GitHub Enterprise一起使用?理想情況下使用身份驗證令牌?package mainimport ( "fmt" "io/ioutil" git "gopkg.in/src-d/go-git.v4" "gopkg.in/src-d/go-git.v4/plumbing" "gopkg.in/src-d/go-git.v4/plumbing/transport/http")const ( repoURL = "https://github.mycompany.net/my-org/myrepo.git" githubAccessToken = "atokenthatisdefinitelyvalid")func main() { dir, _ := ioutil.TempDir("", "temp_dir") options := &git.CloneOptions{ Auth: &http.TokenAuth{Token: githubAccessToken}, URL: repoURL, Depth: 500, ReferenceName: plumbing.ReferenceName("refs/heads/master"), SingleBranch: true, Tags: git.NoTags, } _, err := git.PlainClone(dir, false, options) fmt.Println(err)}
使用go-git從GitHub Enterprise克隆存儲庫
慕蓋茨4494581
2021-03-28 17:19:53