aboutsummaryrefslogtreecommitdiffstats
path: root/examples/basic
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-12-12 15:50:03 +0100
committerGitHub <noreply@github.com>2016-12-12 15:50:03 +0100
commit3967812bd0de40330dfbb9e1a7d14d4073cc1b10 (patch)
treedbd5df2a66bdd50df40fd773e1d1ec284483ecfe /examples/basic
parent6f701ecc18909959364b708b8efddd03cf4e809c (diff)
downloadgo-git-3967812bd0de40330dfbb9e1a7d14d4073cc1b10.tar.gz
examples: review, testing and documentation (#176)
* examples reviews, testing and documentation * including the execution on travis, and fix readme * fix example link * including the execution on travis
Diffstat (limited to 'examples/basic')
-rw-r--r--examples/basic/main.go57
1 files changed, 0 insertions, 57 deletions
diff --git a/examples/basic/main.go b/examples/basic/main.go
deleted file mode 100644
index d92002a..0000000
--- a/examples/basic/main.go
+++ /dev/null
@@ -1,57 +0,0 @@
-package main
-
-import (
- "fmt"
- "strings"
-
- "github.com/fatih/color"
-
- "gopkg.in/src-d/go-git.v4"
-)
-
-func main() {
- r, _ := git.NewFilesystemRepository(".git")
-
- // Clone the given repository, creating the remote, the local branches
- // and fetching the objects, exactly as:
- // > git clone https://github.com/git-fixtures/basic.git
- color.Blue("git clone https://github.com/git-fixtures/basic.git")
-
- r.Clone(&git.CloneOptions{
- URL: "https://github.com/git-fixtures/basic.git",
- })
-
- // Getting the latest commit on the current branch
- // > git log -1
- color.Blue("git log -1")
-
- // ... retrieving the branch being pointed by HEAD
- ref, _ := r.Head()
- // ... retrieving the commit object
- commit, err := r.Commit(ref.Hash())
- fmt.Println(commit, err)
-
- // List the tree from HEAD
- // > git ls-tree -r HEAD
- color.Blue("git ls-tree -r HEAD")
-
- // ... retrieve the tree from the commit
- tree, _ := commit.Tree()
- // ... get the files iterator and print the file
- tree.Files().ForEach(func(f *git.File) error {
- fmt.Printf("100644 blob %s %s\n", f.Hash, f.Name)
- return nil
- })
-
- // List the history of the repository
- // > git log --oneline
- color.Blue("git log --oneline")
-
- commits, _ := commit.History()
- for _, c := range commits {
- hash := c.Hash.String()
- line := strings.Split(c.Message, "\n")
- fmt.Println(hash[:7], line[0])
- }
-
-}