aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/vcs/git.go
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2025-06-16 19:10:37 +0200
committerAleksandr Nogikh <nogikh@google.com>2025-06-17 15:50:14 +0000
commite77fae1501ac8002d344f33dfea3a7b8444d74fc (patch)
tree459acded307cef0fdd09e203ff68c222a75aec6a /pkg/vcs/git.go
parenta56861338db0dfa2a57fef7156de565a2a6ae99e (diff)
pkg/vcs: don't re-clone on network errors
There's no sense to react to `git checkout` or `git fetch` which failed due to network problems by re-cloning the whole repository - that operation will fail just as well. Detect at least one kind of such problems and just return an error from the Poll() method, without wiping everything out. For now, don't add tests as we would need some real remote git server implementation to properly test it. Using a folder as a "remote" repository, like we do in other tests, won't ever trigger networking errors. Closes #6099.
Diffstat (limited to 'pkg/vcs/git.go')
-rw-r--r--pkg/vcs/git.go12
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