blob: d4b54dc523d9744a20c60b5e0a0e17f336accfc6 (
plain) (
tree)
|
|
package main
import (
"fmt"
"os"
"srcd.works/go-git.v4"
. "srcd.works/go-git.v4/_examples"
)
// 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)
// ... retrieving the commit object
commit, err := r.CommitObject(ref.Hash())
CheckIfError(err)
// ... calculating the commit history
commits, err := commit.History()
CheckIfError(err)
fmt.Println(len(commits))
}
|