Skip to content
Snippets Groups Projects
Select Git revision
  • v1.3.2
  • debian default protected
  • pristine-tar
  • upstream
  • master
  • debian/1.4.1-1
  • upstream/1.4.1
  • v1.4.2b1
  • v1.4.2b0
  • v1.4.1
  • v1.4.1b2
  • v1.4.1b1
  • v1.4.1b0
  • v1.4.0
  • v1.4.0b3
  • v1.4.0b2
  • v1.4.0b1
  • v1.4.0b0
  • v1.3.5
  • v1.3.5b0
  • v1.3.4
  • v1.3.4rc0
  • v1.3.4b0
  • v1.3.3
24 results

getting_data.rst

Blame
  • main.go 1.30 KiB
    package main
    
    import (
    	"crypto/tls"
    	"fmt"
    	"net/http"
    	"os"
    	"time"
    
    	"github.com/go-git/go-git/v5"
    	. "github.com/go-git/go-git/v5/_examples"
    	"github.com/go-git/go-git/v5/plumbing/transport/client"
    	githttp "github.com/go-git/go-git/v5/plumbing/transport/http"
    	"github.com/go-git/go-git/v5/storage/memory"
    )
    
    // Here is an example to configure http client according to our own needs.
    func main() {
    	CheckArgs("<url>")
    	url := os.Args[1]
    
    	// Create a custom http(s) client with your config
    	customClient := &http.Client{
    		// accept any certificate (might be useful for testing)
    		Transport: &http.Transport{
    			TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
    		},
    
    		// 15 second timeout
    		Timeout: 15 * time.Second,
    
    		// don't follow redirect
    		CheckRedirect: func(req *http.Request, via []*http.Request) error {
    			return http.ErrUseLastResponse
    		},
    	}
    
    	// Override http(s) default protocol to use our custom client
    	client.InstallProtocol("https", githttp.NewClient(customClient))
    
    	// Clone repository using the new client if the protocol is https://
    	Info("git clone %s", url)
    
    	r, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{URL: url})
    	CheckIfError(err)
    
    	// Retrieve the branch pointed by HEAD
    	Info("git rev-parse HEAD")
    
    	head, err := r.Head()
    	CheckIfError(err)
    	fmt.Println(head.Hash())
    }