aboutsummaryrefslogtreecommitdiffstats
path: root/examples/remotes/main.go
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/remotes/main.go
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/remotes/main.go')
-rw-r--r--examples/remotes/main.go44
1 files changed, 25 insertions, 19 deletions
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)
}