From a6197bd8c459c7d10717bd9486c17f6c8b3f7f88 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Tue, 31 Jan 2017 23:09:28 +0100 Subject: documentation changes --- _examples/open/main.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 _examples/open/main.go (limited to '_examples/open/main.go') diff --git a/_examples/open/main.go b/_examples/open/main.go new file mode 100644 index 0000000..aa51935 --- /dev/null +++ b/_examples/open/main.go @@ -0,0 +1,35 @@ +package main + +import ( + "fmt" + "os" + + "srcd.works/go-git.v4" + . "srcd.works/go-git.v4/examples" +) + +func main() { + CheckArgs("") + 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.Commit(ref.Hash()) + CheckIfError(err) + + // ... calculating the commit history + commits, err := commit.History() + CheckIfError(err) + + fmt.Println(len(commits)) +} -- cgit