aboutsummaryrefslogtreecommitdiffstats
path: root/_examples/log/main.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-01-31 23:09:28 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2017-01-31 23:09:52 +0100
commita6197bd8c459c7d10717bd9486c17f6c8b3f7f88 (patch)
tree63180ec210c66fda317c87197d2f6bab508406b6 /_examples/log/main.go
parent2308066c28d3cbbfb472fb634c3e10a1c7786cfc (diff)
downloadgo-git-a6197bd8c459c7d10717bd9486c17f6c8b3f7f88.tar.gz
documentation changes
Diffstat (limited to '_examples/log/main.go')
-rw-r--r--_examples/log/main.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/_examples/log/main.go b/_examples/log/main.go
new file mode 100644
index 0000000..486e8c9
--- /dev/null
+++ b/_examples/log/main.go
@@ -0,0 +1,39 @@
+package main
+
+import (
+ "fmt"
+
+ "srcd.works/go-git.v4"
+ . "srcd.works/go-git.v4/examples"
+ "srcd.works/go-git.v4/storage/memory"
+)
+
+func main() {
+ // Clones the given repository, creating the remote, the local branches
+ // and fetching the objects, everything in memory:
+ Info("git clone https://github.com/src-d/go-siva")
+ r, err := git.Clone(memory.NewStorage(), nil, &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)
+ }
+}