From 3967812bd0de40330dfbb9e1a7d14d4073cc1b10 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Mon, 12 Dec 2016 15:50:03 +0100 Subject: 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 --- examples/remotes/main.go | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) (limited to 'examples/remotes/main.go') diff --git a/examples/remotes/main.go b/examples/remotes/main.go index 43b127f..c0d71f5 100644 --- a/examples/remotes/main.go +++ b/examples/remotes/main.go @@ -3,50 +3,53 @@ package main import ( "fmt" - "github.com/fatih/color" - "gopkg.in/src-d/go-git.v4" "gopkg.in/src-d/go-git.v4/config" + . "gopkg.in/src-d/go-git.v4/examples" "gopkg.in/src-d/go-git.v4/plumbing" ) func main() { // Create a new repository - color.Blue("git init") + Info("git init") r := git.NewMemoryRepository() // Add a new remote, with the default fetch refspec - // > git remote add example https://github.com/git-fixtures/basic.git - color.Blue("git remote add example https://github.com/git-fixtures/basic.git") + Info("git remote add example https://github.com/git-fixtures/basic.git") - r.CreateRemote(&config.RemoteConfig{ + _, err := r.CreateRemote(&config.RemoteConfig{ Name: "example", URL: "https://github.com/git-fixtures/basic.git", }) + CheckIfError(err) + // List remotes from a repository - // > git remotes -v - color.Blue("git remotes -v") + Info("git remotes -v") + + list, err := r.Remotes() + CheckIfError(err) - list, _ := r.Remotes() for _, r := range list { fmt.Println(r) } // Pull using the create repository - // > git pull example - color.Blue("git pull example") - - r.Pull(&git.PullOptions{ + Info("git pull example") + err = r.Pull(&git.PullOptions{ RemoteName: "example", }) + CheckIfError(err) + // List the branches // > git show-ref - color.Blue("git show-ref") + Info("git show-ref") + + refs, err := r.References() + CheckIfError(err) - refs, _ := r.References() - refs.ForEach(func(ref *plumbing.Reference) error { + err = refs.ForEach(func(ref *plumbing.Reference) error { // The HEAD is omitted in a `git show-ref` so we ignore the symbolic // references, the HEAD if ref.Type() == plumbing.SymbolicReference { @@ -57,8 +60,11 @@ func main() { return nil }) + CheckIfError(err) + // Delete the example remote - // > git remote rm example - color.Blue("git remote rm example") - r.DeleteRemote("example") + Info("git remote rm example") + + err = r.DeleteRemote("example") + CheckIfError(err) } -- cgit