| package main |
| |
| import ( |
| "fmt" |
| "os" |
| |
| "gopkg.in/src-d/go-git.v4" |
| . "gopkg.in/src-d/go-git.v4/examples" |
| ) |
| |
| func main() { |
| CheckArgs("<path>") |
| path := os.Args[1] |
| |
| // We instance a new repository targeting the given path (the .git folder) |
| r, err := git.NewFilesystemRepository(path) |
| CheckIfError(err) |
| |
| // Length of the HEAD history |
| Info("git rev-list HEAD --count") |
| |
| // ... retrieving the HEAD reference |
| ref, err := r.Head() |
| CheckIfError(err) |
| |
| // ... retrieving the commit object |
| commit, err := r.Commit(ref.Hash()) |
| CheckIfError(err) |
| |
| // ... calculating the commit history |
| commits, err := commit.History() |
| CheckIfError(err) |
| |
| fmt.Println(len(commits)) |
| } |