summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-12-01 13:20:21 +0000
committerGerrit Code Review <review@openstack.org>2018-12-01 13:20:21 +0000
commit300915538c04ebe782da31464fa937b204579d6a (patch)
tree40964622c48584feadef065c29ffc0382ff2f1e4
parentc996adcb5ee8dc068206539272e6b688dd710054 (diff)
parent477fe80dc0c25dec866df181eb229ea88aa4f443 (diff)
Merge "Fix permanently broken git cache"
-rw-r--r--tests/unit/test_merger_repo.py8
-rw-r--r--zuul/merger/merger.py10
2 files changed, 17 insertions, 1 deletions
diff --git a/tests/unit/test_merger_repo.py b/tests/unit/test_merger_repo.py
index 265c679..06c6314 100644
--- a/tests/unit/test_merger_repo.py
+++ b/tests/unit/test_merger_repo.py
@@ -179,6 +179,14 @@ class TestMergerRepo(ZuulTestCase):
179 # And now reset the repo again. This should not crash 179 # And now reset the repo again. This should not crash
180 work_repo.reset() 180 work_repo.reset()
181 181
182 # Now open a cache repo and break it in a way that git.Repo is happy
183 # at first but git won't be.
184 merger = self.executor_server.merger
185 cache_repo = merger.getRepo('gerrit', 'org/project')
186 with open(os.path.join(cache_repo.local_path, '.git/HEAD'), 'w'):
187 pass
188 cache_repo.update()
189
182 def test_broken_gitmodules(self): 190 def test_broken_gitmodules(self):
183 parent_path = os.path.join(self.upstream_root, 'org/project1') 191 parent_path = os.path.join(self.upstream_root, 'org/project1')
184 work_repo = Repo(parent_path, self.workspace_root, 192 work_repo = Repo(parent_path, self.workspace_root,
diff --git a/zuul/merger/merger.py b/zuul/merger/merger.py
index ab898b9..fff7e16 100644
--- a/zuul/merger/merger.py
+++ b/zuul/merger/merger.py
@@ -212,13 +212,21 @@ class Repo(object):
212 break 212 break
213 except Exception as e: 213 except Exception as e:
214 if attempt < self.retry_attempts: 214 if attempt < self.retry_attempts:
215 if 'fatal: bad config' in e.stderr: 215 if 'fatal: bad config' in e.stderr.lower():
216 # This error can be introduced by a merge conflict 216 # This error can be introduced by a merge conflict
217 # in the .gitmodules which was left by the last 217 # in the .gitmodules which was left by the last
218 # merge operation. In this case reset and clean 218 # merge operation. In this case reset and clean
219 # the repo and try again immediately. 219 # the repo and try again immediately.
220 reset_repo_to_head(repo) 220 reset_repo_to_head(repo)
221 repo.git.clean('-x', '-f', '-d') 221 repo.git.clean('-x', '-f', '-d')
222 elif 'fatal: not a git repository' in e.stderr.lower():
223 # If we get here the git.Repo object was happy with its
224 # lightweight way of checking if this is a valid git
225 # repository. However if e.g. the .git/HEAD file is
226 # empty git operations fail. So there is something
227 # fundamentally broken with the repo and we need to
228 # delete it before advancing to _ensure_cloned.
229 shutil.rmtree(self.local_path)
222 else: 230 else:
223 time.sleep(self.retry_interval) 231 time.sleep(self.retry_interval)
224 self.log.exception("Retry %s: Fetch %s %s %s" % ( 232 self.log.exception("Retry %s: Fetch %s %s %s" % (