fork of go-git with some jj specific features
at v5.2.0 40 lines 1.1 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/transport/http" 10) 11 12func main() { 13 CheckArgs("<url>", "<directory>", "<github_access_token>") 14 url, directory, token := os.Args[1], os.Args[2], os.Args[3] 15 16 // Clone the given repository to the given directory 17 Info("git clone %s %s", url, directory) 18 19 r, err := git.PlainClone(directory, false, &git.CloneOptions{ 20 // The intended use of a GitHub personal access token is in replace of your password 21 // because access tokens can easily be revoked. 22 // https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/ 23 Auth: &http.BasicAuth{ 24 Username: "abc123", // yes, this can be anything except an empty string 25 Password: token, 26 }, 27 URL: url, 28 Progress: os.Stdout, 29 }) 30 CheckIfError(err) 31 32 // ... retrieving the branch being pointed by HEAD 33 ref, err := r.Head() 34 CheckIfError(err) 35 // ... retrieving the commit object 36 commit, err := r.CommitObject(ref.Hash()) 37 CheckIfError(err) 38 39 fmt.Println(commit) 40}