Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit efd2792

Browse files
committed
examples: basic
1 parent 56f5e4e commit efd2792

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

examples/basic/main.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"io"
6+
"os"
7+
8+
"gopkg.in/src-d/go-git.v2"
9+
)
10+
11+
func main() {
12+
fmt.Printf("Retrieving %q ...\n", os.Args[2])
13+
r, err := git.NewRepository(os.Args[2], nil)
14+
if err != nil {
15+
panic(err)
16+
}
17+
18+
if err := r.Pull("origin", "refs/heads/master"); err != nil {
19+
panic(err)
20+
}
21+
22+
dumpCommits(r)
23+
}
24+
25+
func dumpCommits(r *git.Repository) {
26+
iter := r.Commits()
27+
defer iter.Close()
28+
29+
for {
30+
commit, err := iter.Next()
31+
if err != nil {
32+
if err == io.EOF {
33+
break
34+
}
35+
36+
panic(err)
37+
}
38+
39+
fmt.Println(commit)
40+
}
41+
}

0 commit comments

Comments
 (0)