fork of go-git with some jj specific features
at v4.7.0 42 lines 827 B view raw
1package main 2 3import ( 4 "fmt" 5 "os" 6 7 "gopkg.in/src-d/go-git.v4" 8 . "gopkg.in/src-d/go-git.v4/_examples" 9 "gopkg.in/src-d/go-git.v4/plumbing/object" 10) 11 12// Open an existing repository in a specific folder. 13func main() { 14 CheckArgs("<path>") 15 path := os.Args[1] 16 17 // We instance a new repository targeting the given path (the .git folder) 18 r, err := git.PlainOpen(path) 19 CheckIfError(err) 20 21 // Length of the HEAD history 22 Info("git rev-list HEAD --count") 23 24 // ... retrieving the HEAD reference 25 ref, err := r.Head() 26 CheckIfError(err) 27 28 // ... retrieves the commit history 29 cIter, err := r.Log(&git.LogOptions{From: ref.Hash()}) 30 CheckIfError(err) 31 32 // ... just iterates over the commits 33 var cCount int 34 err = cIter.ForEach(func(c *object.Commit) error { 35 cCount++ 36 37 return nil 38 }) 39 CheckIfError(err) 40 41 fmt.Println(cCount) 42}