aboutsummaryrefslogtreecommitdiffstats
path: root/examples/log/main.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-12-13 16:01:35 +0100
committerGitHub <noreply@github.com>2016-12-13 16:01:35 +0100
commit40875ee0df345468f36cb00d54820d622b37cbc5 (patch)
treef1089615de9095f3f14f9eeacd04f6866830f876 /examples/log/main.go
parent920dc0253f2d4e00779ed895d06a7a72e0e8ab66 (diff)
downloadgo-git-40875ee0df345468f36cb00d54820d622b37cbc5.tar.gz
readme and log example (#181)
* readme and log example * changes * changes
Diffstat (limited to 'examples/log/main.go')
-rw-r--r--examples/log/main.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/examples/log/main.go b/examples/log/main.go
new file mode 100644
index 0000000..6ab0bb7
--- /dev/null
+++ b/examples/log/main.go
@@ -0,0 +1,40 @@
+package main
+
+import (
+ "fmt"
+
+ "gopkg.in/src-d/go-git.v4"
+ . "gopkg.in/src-d/go-git.v4/examples"
+)
+
+func main() {
+ // Instances an in-memory git repository
+ r := git.NewMemoryRepository()
+
+ // Clones the given repository, creating the remote, the local branches
+ // and fetching the objects, exactly as:
+ Info("git clone https://github.com/src-d/go-siva")
+
+ err := r.Clone(&git.CloneOptions{URL: "https://github.com/src-d/go-siva"})
+ CheckIfError(err)
+
+ // Gets the HEAD history from HEAD, just like does:
+ Info("git log")
+
+ // ... retrieves the branch pointed by HEAD
+ ref, err := r.Head()
+ CheckIfError(err)
+
+ // ... retrieves the commit object
+ commit, err := r.Commit(ref.Hash())
+ CheckIfError(err)
+
+ // ... retrieves the commit history
+ history, err := commit.History()
+ CheckIfError(err)
+
+ // ... just iterates over the commits, printing it
+ for _, c := range history {
+ fmt.Println(c)
+ }
+}