diff --git a/Gopkg.lock b/Gopkg.lock index 32a69a14..2c21147e 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -1,6 +1,12 @@ # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. +[[projects]] + name = "github.com/avast/retry-go" + packages = ["."] + revision = "5469272a8171235352a56af37e5f7facf814423f" + version = "1.0.1" + [[projects]] name = "github.com/cpuguy83/go-md2man" packages = ["md2man"] @@ -28,7 +34,18 @@ [[projects]] branch = "master" name = "github.com/hashicorp/hcl" - packages = [".","hcl/ast","hcl/parser","hcl/printer","hcl/scanner","hcl/strconv","hcl/token","json/parser","json/scanner","json/token"] + packages = [ + ".", + "hcl/ast", + "hcl/parser", + "hcl/printer", + "hcl/scanner", + "hcl/strconv", + "hcl/token", + "json/parser", + "json/scanner", + "json/token" + ] revision = "23c074d0eceb2b8a5bfdbb271ab780cde70f05a8" [[projects]] @@ -81,7 +98,10 @@ [[projects]] name = "github.com/spf13/afero" - packages = [".","mem"] + packages = [ + ".", + "mem" + ] revision = "8d919cbe7e2627e417f3e45c3c0e489a5b7e2536" version = "v1.0.0" @@ -94,7 +114,10 @@ [[projects]] branch = "master" name = "github.com/spf13/cobra" - packages = [".","doc"] + packages = [ + ".", + "doc" + ] revision = "fd32f09af19efc9b1279c54e0d8ed23f66232a15" [[projects]] @@ -117,7 +140,10 @@ [[projects]] name = "github.com/stretchr/testify" - packages = ["assert","require"] + packages = [ + "assert", + "require" + ] revision = "69483b4bd14f5845b5a1e55bca19e954e827f1d0" version = "v1.1.4" @@ -141,13 +167,23 @@ [[projects]] branch = "master" name = "golang.org/x/sys" - packages = ["unix","windows"] + packages = [ + "unix", + "windows" + ] revision = "0dd5e194bbf5eb84a39666eb4c98a4d007e4203a" [[projects]] branch = "master" name = "golang.org/x/text" - packages = ["internal/gen","internal/triegen","internal/ucd","transform","unicode/cldr","unicode/norm"] + packages = [ + "internal/gen", + "internal/triegen", + "internal/ucd", + "transform", + "unicode/cldr", + "unicode/norm" + ] revision = "be25de41fadfae372d6470bda81ca6beb55ef551" [[projects]] @@ -159,6 +195,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "1bf9d1f6c3b6b3bd13691352d53ed885bb52bc710768ed20ad56a3502341fb1e" + inputs-digest = "f902c44fdfda24711d2fc77ec47941bc42dc0a0f1aad18922657e7ef5b1542f0" solver-name = "gps-cdcl" solver-version = 1 diff --git a/cmd/clone.go b/cmd/clone.go index 05c5bd21..65cbb908 100644 --- a/cmd/clone.go +++ b/cmd/clone.go @@ -3,7 +3,9 @@ package cmd import ( "log" "strings" + "time" + retry "github.com/avast/retry-go" "github.com/spf13/cobra" "github.com/zaquestion/lab/internal/git" "github.com/zaquestion/lab/internal/gitlab" @@ -29,7 +31,11 @@ var cloneCmd = &cobra.Command{ log.Fatal(err) } path := project.SSHURLToRepo - err = git.New(append([]string{"clone", path}, args[1:]...)...).Run() + // #116 retry on the cases where we found a project but clone + // failed over ssh + err = retry.Do(func() error { + return git.New(append([]string{"clone", path}, args[1:]...)...).Run() + }, retry.Attempts(3), retry.Delay(time.Second), retry.Units(time.Nanosecond)) if err != nil { log.Fatal(err) } diff --git a/internal/git/git.go b/internal/git/git.go index 9ef3d94c..887b101a 100644 --- a/internal/git/git.go +++ b/internal/git/git.go @@ -8,7 +8,9 @@ import ( "os/exec" "path/filepath" "strings" + "time" + retry "github.com/avast/retry-go" "github.com/pkg/errors" "github.com/tcnksm/go-gitconfig" ) @@ -183,9 +185,13 @@ func RemoteAdd(name, url, dir string) error { return err } fmt.Println("Updating", name) - cmd = New("fetch", name) - cmd.Dir = dir - if err := cmd.Run(); err != nil { + + err := retry.Do(func() error { + cmd = New("fetch", name) + cmd.Dir = dir + return cmd.Run() + }, retry.Attempts(3), retry.Delay(time.Second), retry.Units(time.Nanosecond)) + if err != nil { return err } fmt.Println("new remote:", name)