aboutsummaryrefslogtreecommitdiffstats
path: root/examples/open/main.go
blob: fa11844cf04e966c13837f27642eb6efe2f2dedb (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
32
33
34
35
36
37
38
39
40
package main

import (
	"fmt"
	"os"
	"path/filepath"

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

func main() {
	path, _ := filepath.Abs(os.Args[1])
	fmt.Printf("Opening repository %q ...\n", path)

	r, err := git.NewFilesystemRepository(path)
	if err != nil {
		panic(err)
	}

	iter, err := r.Commits()
	if err != nil {
		panic(err)
	}

	defer iter.Close()

	var count = 0
	err = iter.ForEach(func(commit *git.Commit) error {
		count++
		fmt.Println(commit)

		return nil
	})

	if err != nil {
		panic(err)
	}

	fmt.Println("total commits:", count)
}