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

Commit bcefb5b

Browse files
committed
documentation
1 parent 74b8b53 commit bcefb5b

File tree

4 files changed

+66
-10
lines changed

4 files changed

+66
-10
lines changed

README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,23 @@ go get -u gopkg.in/src-d/go-git.v3/...
3737
Examples
3838
--------
3939

40-
Basic example: retrieving the commits for a given repository:
40+
Retrieving the commits for a given repository:
4141

4242
```go
4343
r, err := git.NewRepository("https://github.com/src-d/go-git", nil)
4444
if err != nil {
4545
panic(err)
4646
}
4747

48-
if err := r.Pull("origin", "refs/heads/master"); err != nil {
48+
if err := r.PullDefault(); err != nil {
4949
panic(err)
5050
}
5151

5252
iter := r.Commits()
5353
defer iter.Close()
5454

5555
for {
56+
//the commits are not shorted in any special order
5657
commit, err := iter.Next()
5758
if err != nil {
5859
if err == io.EOF {
@@ -86,6 +87,32 @@ Date: 2015-12-11 17:57:10 +0100 +0100
8687
...
8788
```
8889

90+
Retrieving the latest commit for a given repository:
91+
92+
```go
93+
r, err := git.NewRepository("https://github.com/src-d/go-git", nil)
94+
if err != nil {
95+
panic(err)
96+
}
97+
98+
if err := r.PullDefault(); err != nil {
99+
panic(err)
100+
}
101+
102+
hash, err := r.Remotes[git.DefaultRemoteName].Head()
103+
if err != nil {
104+
panic(err)
105+
}
106+
107+
commit, err := r.Commit(hash)
108+
if err != nil {
109+
panic(err)
110+
}
111+
112+
fmt.Println(commit)
113+
```
114+
115+
89116
Acknowledgements
90117
----------------
91118

doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@
3232
// fmt.Println(commit)
3333
// }
3434
// }
35-
package git
35+
package git // import "gopkg.in/src-d/go-git.v3"

examples/basic/main.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,21 @@ import (
99
)
1010

1111
func main() {
12-
fmt.Printf("Retrieving %q ...\n", os.Args[2])
13-
r, err := git.NewRepository(os.Args[2], nil)
12+
fmt.Printf("Retrieving %q ...\n", os.Args[1])
13+
r, err := git.NewRepository(os.Args[1], nil)
1414
if err != nil {
1515
panic(err)
1616
}
1717

18-
if err := r.Pull("origin", "refs/heads/master"); err != nil {
18+
if err := r.PullDefault(); err != nil {
1919
panic(err)
2020
}
2121

22-
dumpCommits(r)
23-
}
24-
25-
func dumpCommits(r *git.Repository) {
2622
iter := r.Commits()
2723
defer iter.Close()
2824

2925
for {
26+
//the commits are not shorted in any special order
3027
commit, err := iter.Next()
3128
if err != nil {
3229
if err == io.EOF {

examples/latest/latest.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"gopkg.in/src-d/go-git.v3"
8+
)
9+
10+
func main() {
11+
fmt.Printf("Retrieving latest commit from: %q ...\n", os.Args[1])
12+
r, err := git.NewRepository(os.Args[1], nil)
13+
if err != nil {
14+
panic(err)
15+
}
16+
17+
if err := r.Pull(git.DefaultRemoteName, "refs/heads/master"); err != nil {
18+
panic(err)
19+
}
20+
21+
hash, err := r.Remotes[git.DefaultRemoteName].Head()
22+
if err != nil {
23+
panic(err)
24+
}
25+
26+
commit, err := r.Commit(hash)
27+
if err != nil {
28+
panic(err)
29+
}
30+
31+
fmt.Println(commit)
32+
}

0 commit comments

Comments
 (0)