aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-04-25 09:01:28 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-04-25 09:01:28 +0200
commitbcefb5bf829b841d9d12a27a06099b67c609b5f8 (patch)
tree273cad16130aa6cd05952e1aca88b9f41dc135c9 /README.md
parent74b8b53b28d444542edc77e0beec19bbab8e8037 (diff)
downloadgo-git-bcefb5bf829b841d9d12a27a06099b67c609b5f8.tar.gz
documentation
Diffstat (limited to 'README.md')
-rw-r--r--README.md31
1 files changed, 29 insertions, 2 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
----------------