fork of go-git with some jj specific features
at v5.13.2 56 lines 1.7 kB view raw
1package main 2 3import ( 4 "fmt" 5 "os" 6 7 git "github.com/go-git/go-git/v5" 8 . "github.com/go-git/go-git/v5/_examples" 9 "github.com/go-git/go-git/v5/plumbing/protocol/packp/capability" 10 "github.com/go-git/go-git/v5/plumbing/transport" 11 "github.com/go-git/go-git/v5/plumbing/transport/http" 12) 13 14func main() { 15 CheckArgs("<url>", "<directory>", "<azuredevops_username>", "<azuredevops_password>") 16 url, directory, username, password := os.Args[1], os.Args[2], os.Args[3], os.Args[4] 17 18 // Clone the given repository to the given directory 19 Info("git clone %s %s", url, directory) 20 21 // Azure DevOps requires capabilities multi_ack / multi_ack_detailed, 22 // which are not fully implemented and by default are included in 23 // transport.UnsupportedCapabilities. 24 // 25 // The initial clone operations require a full download of the repository, 26 // and therefore those unsupported capabilities are not as crucial, so 27 // by removing them from that list allows for the first clone to work 28 // successfully. 29 // 30 // Additional fetches will yield issues, therefore work always from a clean 31 // clone until those capabilities are fully supported. 32 // 33 // New commits and pushes against a remote worked without any issues. 34 transport.UnsupportedCapabilities = []capability.Capability{ 35 capability.ThinPack, 36 } 37 38 r, err := git.PlainClone(directory, false, &git.CloneOptions{ 39 Auth: &http.BasicAuth{ 40 Username: username, 41 Password: password, 42 }, 43 URL: url, 44 Progress: os.Stdout, 45 }) 46 CheckIfError(err) 47 48 // ... retrieving the branch being pointed by HEAD 49 ref, err := r.Head() 50 CheckIfError(err) 51 // ... retrieving the commit object 52 commit, err := r.CommitObject(ref.Hash()) 53 CheckIfError(err) 54 55 fmt.Println(commit) 56}