diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-12-12 15:50:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-12 15:50:03 +0100 |
commit | 3967812bd0de40330dfbb9e1a7d14d4073cc1b10 (patch) | |
tree | dbd5df2a66bdd50df40fd773e1d1ec284483ecfe /examples/open | |
parent | 6f701ecc18909959364b708b8efddd03cf4e809c (diff) | |
download | go-git-3967812bd0de40330dfbb9e1a7d14d4073cc1b10.tar.gz |
examples: review, testing and documentation (#176)
* examples reviews, testing and documentation
* including the execution on travis, and fix readme
* fix example link
* including the execution on travis
Diffstat (limited to 'examples/open')
-rw-r--r-- | examples/open/main.go | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/examples/open/main.go b/examples/open/main.go index fa11844..90fd406 100644 --- a/examples/open/main.go +++ b/examples/open/main.go @@ -3,38 +3,33 @@ package main import ( "fmt" "os" - "path/filepath" "gopkg.in/src-d/go-git.v4" + . "gopkg.in/src-d/go-git.v4/examples" ) func main() { - path, _ := filepath.Abs(os.Args[1]) - fmt.Printf("Opening repository %q ...\n", path) + CheckArgs("<path>") + path := os.Args[1] + // We instance a new repository targeting the given path (the .git folder) r, err := git.NewFilesystemRepository(path) - if err != nil { - panic(err) - } + CheckIfError(err) - iter, err := r.Commits() - if err != nil { - panic(err) - } + // Length of the HEAD history + Info("git rev-list HEAD --count") - defer iter.Close() + // ... retrieving the HEAD reference + ref, err := r.Head() + CheckIfError(err) - var count = 0 - err = iter.ForEach(func(commit *git.Commit) error { - count++ - fmt.Println(commit) + // ... retrieving the commit object + commit, err := r.Commit(ref.Hash()) + CheckIfError(err) - return nil - }) + // ... calculating the commit history + commits, err := commit.History() + CheckIfError(err) - if err != nil { - panic(err) - } - - fmt.Println("total commits:", count) + fmt.Println(len(commits)) } |