fork of go-git with some jj specific features
at main 1.3 kB view raw
1package main 2 3import ( 4 "crypto/tls" 5 "fmt" 6 "net/http" 7 "os" 8 "time" 9 10 "github.com/go-git/go-git/v5" 11 . "github.com/go-git/go-git/v5/_examples" 12 "github.com/go-git/go-git/v5/plumbing/transport" 13 githttp "github.com/go-git/go-git/v5/plumbing/transport/http" 14 "github.com/go-git/go-git/v5/storage/memory" 15) 16 17// Here is an example to configure http client according to our own needs. 18func main() { 19 CheckArgs("<url>") 20 url := os.Args[1] 21 22 // Create a custom http(s) client with your config 23 customClient := &http.Client{ 24 // accept any certificate (might be useful for testing) 25 Transport: &http.Transport{ 26 TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, 27 }, 28 29 // 15 second timeout 30 Timeout: 15 * time.Second, 31 32 // don't follow redirect 33 CheckRedirect: func(req *http.Request, via []*http.Request) error { 34 return http.ErrUseLastResponse 35 }, 36 } 37 38 // Override http(s) default protocol to use our custom client 39 transport.Register("https", githttp.NewClient(customClient)) 40 41 // Clone repository using the new client if the protocol is https:// 42 Info("git clone %s", url) 43 44 r, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{URL: url}) 45 CheckIfError(err) 46 47 // Retrieve the branch pointed by HEAD 48 Info("git rev-parse HEAD") 49 50 head, err := r.Head() 51 CheckIfError(err) 52 fmt.Println(head.Hash()) 53}