summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIbrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>2019-01-02 22:34:19 +0300
committerIbrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>2019-01-02 22:34:19 +0300
commit6bbe6c3968040153f08ea9835889e151971466d7 (patch)
tree7cf9e419dc1757a3d810a56d219453627397a898
parentrefactor according to good practices (diff)
downloadgitbatch-6bbe6c3968040153f08ea9835889e151971466d7.tar.gz
add failover to pull/fetch
-rw-r--r--pkg/git/cmd-fetch.go2
-rw-r--r--pkg/git/cmd-pull.go14
2 files changed, 14 insertions, 2 deletions
diff --git a/pkg/git/cmd-fetch.go b/pkg/git/cmd-fetch.go
index 2c66c1c..6090f7c 100644
--- a/pkg/git/cmd-fetch.go
+++ b/pkg/git/cmd-fetch.go
@@ -152,7 +152,7 @@ func fetchWithGoGit(e *RepoEntity, options FetchOptions, refspec string) (err er
return ErrAuthenticationRequired
} else {
log.Warn(err.Error())
- return err
+ return fetchWithGit(e, options)
}
}
diff --git a/pkg/git/cmd-pull.go b/pkg/git/cmd-pull.go
index 8f2cf92..0c3954e 100644
--- a/pkg/git/cmd-pull.go
+++ b/pkg/git/cmd-pull.go
@@ -9,6 +9,7 @@ import (
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/transport"
"gopkg.in/src-d/go-git.v4/plumbing/transport/http"
+ "gopkg.in/src-d/go-git.v4/storage/memory"
)
var (
@@ -109,9 +110,19 @@ func pullWithGoGit(e *RepoEntity, options PullOptions) (err error) {
if err = w.Pull(opt); err != nil {
if err == git.NoErrAlreadyUpToDate {
+ // log.Error("error: " + err.Error())
// Already up-to-date
log.Warn(err.Error())
// TODO: submit a PR for this kind of error, this type of catch is lame
+ } else if err == memory.ErrRefHasChanged && pullTryCount < pullMaxTry {
+ pullTryCount++
+ log.Error("trying to fetch")
+ if err := Fetch(e, FetchOptions{
+ RemoteName: options.RemoteName,
+ }); err != nil {
+ return err
+ }
+ return Pull(e, options)
} else if strings.Contains(err.Error(), "SSH_AUTH_SOCK") {
// The env variable SSH_AUTH_SOCK is not defined, maybe git can handle this
return pullWithGit(e, options)
@@ -120,9 +131,10 @@ func pullWithGoGit(e *RepoEntity, options PullOptions) (err error) {
return ErrAuthenticationRequired
} else {
log.Warn(err.Error())
- return err
+ return pullWithGit(e, options)
}
}
+
e.SetState(Success)
return e.Refresh()
}