Merge "Create remote ref when it does not exist"

This commit is contained in:
Zuul 2022-04-13 16:10:03 +00:00 committed by Gerrit Code Review
commit d6ace2cec6
2 changed files with 8 additions and 7 deletions

View File

@ -184,12 +184,14 @@ class TestMergerRepo(ZuulTestCase):
work_repo = Repo(parent_path, self.workspace_root,
'none@example.org', 'User Name', '0', '0')
work_repo.setRemoteRef('master', commit_sha)
work_repo.setRemoteRef('invalid', commit_sha)
# missing remote ref would be created
work_repo.setRemoteRef('missing', commit_sha)
repo = git.Repo(self.workspace_root)
self.assertEqual(repo.remotes.origin.refs.master.commit.hexsha,
commit_sha)
self.assertNotIn('invalid', repo.remotes.origin.refs)
self.assertEqual(repo.remotes.origin.refs.missing.commit.hexsha,
commit_sha)
def test_clone_timeout(self):
parent_path = os.path.join(self.upstream_root, 'org/project1')

View File

@ -509,12 +509,11 @@ class Repo(object):
log = get_annotated_logger(self.log, zuul_event_id)
repo = self.createRepoObject(zuul_event_id)
try:
origin_ref = repo.remotes.origin.refs[branch]
log.debug("Updating remote reference origin/%s to %s", branch, rev)
repo.remotes.origin.refs[branch].commit = rev
except IndexError:
log.warning("No remote ref found for branch %s", branch)
return
log.debug("Updating remote reference %s to %s", origin_ref, rev)
origin_ref.commit = rev
log.warning("No remote ref found for branch %s, creating", branch)
Repo._setRef(f"refs/remotes/origin/{branch}", str(rev), repo)
def deleteRef(self, path, repo=None, zuul_event_id=None):
ref_log = get_annotated_logger(