diff options
| -rw-r--r-- | pkg/vcs/git.go | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/pkg/vcs/git.go b/pkg/vcs/git.go index ef46259f3..72b4a32e6 100644 --- a/pkg/vcs/git.go +++ b/pkg/vcs/git.go @@ -84,8 +84,11 @@ func (git *gitRepo) Poll(repo, branch string) (*Commit, error) { return nil, err } } - if _, err := git.Run("fetch", "--force"); err != nil { - // Something else is wrong, re-clone. + if output, err := git.Run("fetch", "--force"); err != nil { + if git.isNetworkError(output) { + // The clone operation will fail as well, so no sense to re-clone. + return nil, err + } if err := git.clone(repo, branch); err != nil { return nil, err } @@ -99,6 +102,11 @@ func (git *gitRepo) Poll(repo, branch string) (*Commit, error) { return git.Commit(HEAD) } +func (git *gitRepo) isNetworkError(output []byte) bool { + // The list is not exhaustive and is meant to be extended over time. + return bytes.Contains(output, []byte("fatal: read error: Connection reset by peer")) +} + func (git *gitRepo) CheckoutBranch(repo, branch string) (*Commit, error) { if err := git.repair(); err != nil { return nil, err |
