aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md31
-rw-r--r--doc.go2
-rw-r--r--examples/basic/main.go11
-rw-r--r--examples/latest/latest.go32
4 files changed, 66 insertions, 10 deletions
diff --git a/README.md b/README.md
index ba05fe3..57f7f64 100644
--- a/README.md
+++ b/README.md
@@ -37,7 +37,7 @@ go get -u gopkg.in/src-d/go-git.v3/...
Examples
--------
-Basic example: retrieving the commits for a given repository:
+Retrieving the commits for a given repository:
```go
r, err := git.NewRepository("https://github.com/src-d/go-git", nil)
@@ -45,7 +45,7 @@ if err != nil {
panic(err)
}
-if err := r.Pull("origin", "refs/heads/master"); err != nil {
+if err := r.PullDefault(); err != nil {
panic(err)
}
@@ -53,6 +53,7 @@ iter := r.Commits()
defer iter.Close()
for {
+ //the commits are not shorted in any special order
commit, err := iter.Next()
if err != nil {
if err == io.EOF {
@@ -86,6 +87,32 @@ Date: 2015-12-11 17:57:10 +0100 +0100
...
```
+Retrieving the latest commit for a given repository:
+
+```go
+r, err := git.NewRepository("https://github.com/src-d/go-git", nil)
+if err != nil {
+ panic(err)
+}
+
+if err := r.PullDefault(); err != nil {
+ panic(err)
+}
+
+hash, err := r.Remotes[git.DefaultRemoteName].Head()
+if err != nil {
+ panic(err)
+}
+
+commit, err := r.Commit(hash)
+if err != nil {
+ panic(err)
+}
+
+fmt.Println(commit)
+```
+
+
Acknowledgements
----------------
diff --git a/doc.go b/doc.go
index b823943..681ef7d 100644
--- a/doc.go
+++ b/doc.go
@@ -32,4 +32,4 @@
// fmt.Println(commit)
// }
// }
-package git
+package git // import "gopkg.in/src-d/go-git.v3"
diff --git a/examples/basic/main.go b/examples/basic/main.go
index 4b443b2..f5a1c8a 100644
--- a/examples/basic/main.go
+++ b/examples/basic/main.go
@@ -9,24 +9,21 @@ import (
)
func main() {
- fmt.Printf("Retrieving %q ...\n", os.Args[2])
- r, err := git.NewRepository(os.Args[2], nil)
+ fmt.Printf("Retrieving %q ...\n", os.Args[1])
+ r, err := git.NewRepository(os.Args[1], nil)
if err != nil {
panic(err)
}
- if err := r.Pull("origin", "refs/heads/master"); err != nil {
+ if err := r.PullDefault(); err != nil {
panic(err)
}
- dumpCommits(r)
-}
-
-func dumpCommits(r *git.Repository) {
iter := r.Commits()
defer iter.Close()
for {
+ //the commits are not shorted in any special order
commit, err := iter.Next()
if err != nil {
if err == io.EOF {
diff --git a/examples/latest/latest.go b/examples/latest/latest.go
new file mode 100644
index 0000000..84aaf48
--- /dev/null
+++ b/examples/latest/latest.go
@@ -0,0 +1,32 @@
+package main
+
+import (
+ "fmt"
+ "os"
+
+ "gopkg.in/src-d/go-git.v3"
+)
+
+func main() {
+ fmt.Printf("Retrieving latest commit from: %q ...\n", os.Args[1])
+ r, err := git.NewRepository(os.Args[1], nil)
+ if err != nil {
+ panic(err)
+ }
+
+ if err := r.Pull(git.DefaultRemoteName, "refs/heads/master"); err != nil {
+ panic(err)
+ }
+
+ hash, err := r.Remotes[git.DefaultRemoteName].Head()
+ if err != nil {
+ panic(err)
+ }
+
+ commit, err := r.Commit(hash)
+ if err != nil {
+ panic(err)
+ }
+
+ fmt.Println(commit)
+}