aboutsummaryrefslogblamecommitdiffstats
path: root/examples/latest/latest.go
blob: 684ebb784cc22fec86d6f1015eac56fcb061d8a2 (plain) (tree)
1
2
3
4
5
6
7
8
9
10





             
                                  


             



                                                                  



                          





                                                                   


                          
                                            





                           
package main

import (
	"fmt"
	"os"

	"gopkg.in/src-d/go-git.v4"
)

func main() {
	url := os.Args[1]

	fmt.Printf("Retrieving latest commit from: %q ...\n", url)
	r, err := git.NewMemoryRepository()
	if err != nil {
		panic(err)
	}

	if err = r.Clone(&git.CloneOptions{URL: url}); err != nil {
		panic(err)
	}

	head, err := r.Head()
	if err != nil {
		panic(err)
	}

	commit, err := r.Commit(head.Hash())
	if err != nil {
		panic(err)
	}

	fmt.Println(commit)
}