aboutsummaryrefslogtreecommitdiffstats
path: root/examples/latest/latest.go
blob: 05f583ace3a9a078d8150905a53a4d82567f125f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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 := git.NewMemoryRepository()

	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)
}