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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user