mirror of
https://github.com/Luzifer/ansible-role-version.git
synced 2024-12-24 11:31:21 +00:00
42 lines
827 B
Go
42 lines
827 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"gopkg.in/src-d/go-git.v4"
|
|
. "gopkg.in/src-d/go-git.v4/_examples"
|
|
"gopkg.in/src-d/go-git.v4/plumbing/object"
|
|
)
|
|
|
|
// Open an existing repository in a specific folder.
|
|
func main() {
|
|
CheckArgs("<path>")
|
|
path := os.Args[1]
|
|
|
|
// We instance a new repository targeting the given path (the .git folder)
|
|
r, err := git.PlainOpen(path)
|
|
CheckIfError(err)
|
|
|
|
// Length of the HEAD history
|
|
Info("git rev-list HEAD --count")
|
|
|
|
// ... retrieving the HEAD reference
|
|
ref, err := r.Head()
|
|
CheckIfError(err)
|
|
|
|
// ... retrieves the commit history
|
|
cIter, err := r.Log(&git.LogOptions{From: ref.Hash()})
|
|
CheckIfError(err)
|
|
|
|
// ... just iterates over the commits
|
|
var cCount int
|
|
err = cIter.ForEach(func(c *object.Commit) error {
|
|
cCount++
|
|
|
|
return nil
|
|
})
|
|
CheckIfError(err)
|
|
|
|
fmt.Println(cCount)
|
|
}
|