Gracefully handle broken .gitmodule files
The merger can leave broken .gitmodule files behind. This can happen after a merge operation which resulted in a merge conflict in this file. However git fetch fails if this file exists and is corrupt. That permanently breaks all further merge operations on this repo [1]. This can be fixed by checking the error of the git fetch and reset/clean the repo before the next try. [1] Trace: 2018-05-04 11:26:15,865 ERROR zuul.Merger: Unable to reset repo <zuul.merger.merger.Repo object at 0x7f552bc12b00> Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/zuul/merger/merger.py", line 546, in _mergeItem repo.reset() File "/usr/lib/python3.6/site-packages/zuul/merger/merger.py", line 170, in reset self.update() File "/usr/lib/python3.6/site-packages/zuul/merger/merger.py", line 338, in update self._git_fetch(repo, 'origin', tags=True) File "/usr/lib/python3.6/site-packages/zuul/merger/merger.py", line 147, in _git_fetch **kwargs) File "/usr/lib/python3.6/site-packages/git/cmd.py", line 550, in <lambda> return lambda *args, **kwargs: self._call_process(name, *args, **kwargs) File "/usr/lib/python3.6/site-packages/git/cmd.py", line 1009, in _call_process return self.execute(call, **exec_kwargs) File "/usr/lib/python3.6/site-packages/git/cmd.py", line 820, in execute raise GitCommandError(command, status, stderr_value, stdout_value) git.exc.GitCommandError: Cmd('git') failed due to: exit code(128) cmdline: git fetch --tags origin stderr: 'fatal: bad config line 13 in file /var/lib/zuul/merger-git/github/org/project/.gitmodules' Change-Id: Ia4c43a7a4c5108f8d762f39cc830cac5ee1c690a
This commit is contained in:
parent
2693e5d9b0
commit
d357ff3292
@ -181,6 +181,23 @@ class TestMergerRepo(ZuulTestCase):
|
||||
# And now reset the repo again. This should not crash
|
||||
work_repo.reset()
|
||||
|
||||
def test_broken_gitmodules(self):
|
||||
parent_path = os.path.join(self.upstream_root, 'org/project1')
|
||||
work_repo = Repo(parent_path, self.workspace_root,
|
||||
'none@example.org', 'User Name', '0', '0')
|
||||
self.waitUntilSettled()
|
||||
|
||||
# Break the gitmodules
|
||||
path = work_repo.local_path
|
||||
with open(os.path.join(path, '.gitmodules'), 'w') as f:
|
||||
f.write('[submodule "libfoo"]\n'
|
||||
'path = include/foo\n'
|
||||
'---\n'
|
||||
'url = git://example.com/git/lib.git')
|
||||
|
||||
# And now reset the repo again. This should not crash
|
||||
work_repo.reset()
|
||||
|
||||
|
||||
class TestMergerWithAuthUrl(ZuulTestCase):
|
||||
config_file = 'zuul-github-driver.conf'
|
||||
|
@ -157,7 +157,15 @@ class Repo(object):
|
||||
break
|
||||
except Exception as e:
|
||||
if attempt < self.retry_attempts:
|
||||
time.sleep(self.retry_interval)
|
||||
if 'fatal: bad config' in e.stderr:
|
||||
# This error can be introduced by a merge conflict
|
||||
# in the .gitmodules which was left by the last
|
||||
# merge operation. In this case reset and clean
|
||||
# the repo and try again immediately.
|
||||
reset_repo_to_head(repo)
|
||||
repo.git.clean('-x', '-f', '-d')
|
||||
else:
|
||||
time.sleep(self.retry_interval)
|
||||
self.log.exception("Retry %s: Fetch %s %s %s" % (
|
||||
attempt, self.local_path, remote, ref))
|
||||
self._ensure_cloned()
|
||||
|
Loading…
Reference in New Issue
Block a user