aboutsummaryrefslogtreecommitdiffstats
path: root/examples/open
diff options
context:
space:
mode:
Diffstat (limited to 'examples/open')
-rw-r--r--examples/open/main.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/examples/open/main.go b/examples/open/main.go
new file mode 100644
index 0000000..fa11844
--- /dev/null
+++ b/examples/open/main.go
@@ -0,0 +1,40 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+
+ "gopkg.in/src-d/go-git.v4"
+)
+
+func main() {
+ path, _ := filepath.Abs(os.Args[1])
+ fmt.Printf("Opening repository %q ...\n", path)
+
+ r, err := git.NewFilesystemRepository(path)
+ if err != nil {
+ panic(err)
+ }
+
+ iter, err := r.Commits()
+ if err != nil {
+ panic(err)
+ }
+
+ defer iter.Close()
+
+ var count = 0
+ err = iter.ForEach(func(commit *git.Commit) error {
+ count++
+ fmt.Println(commit)
+
+ return nil
+ })
+
+ if err != nil {
+ panic(err)
+ }
+
+ fmt.Println("total commits:", count)
+}