From 7b20c03256552abc1ac2d5ad3fbde4e68c95b762 Mon Sep 17 00:00:00 2001 From: Stephan Kulow Date: Fri, 2 Dec 2022 09:12:11 +0100 Subject: [PATCH] Add force push for the devel branch As devel branches can change in case of factory reverts we need to force push. Factory branch shouldn't be affected, so not force pushing there --- lib/git.py | 10 +++++++--- lib/git_exporter.py | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/git.py b/lib/git.py index b5684d1..87cc5af 100644 --- a/lib/git.py +++ b/lib/git.py @@ -215,13 +215,17 @@ class Git: url = f"gitea@gitea.opensuse.org:{org_name}/{repo_name}.git" self.repo.remotes.create("origin", url) - def push(self): + def push(self, force=False): remo = self.repo.remotes["origin"] keypair = pygit2.KeypairFromAgent("gitea") callbacks = pygit2.RemoteCallbacks(credentials=keypair) refspecs = ["refs/heads/factory"] - if "refs/heads/devel" in self.repo.references: - refspecs.append("refs/heads/devel") + develspec = "refs/heads/devel" + if develspec in self.repo.references: + if force: + refspecs.append(f"+{develspec}:{develspec}") + else: + refspecs.append("{develspec}:{develspec}") remo.push(refspecs, callbacks=callbacks) diff --git a/lib/git_exporter.py b/lib/git_exporter.py index 1df2cc3..533bf4d 100644 --- a/lib/git_exporter.py +++ b/lib/git_exporter.py @@ -86,7 +86,7 @@ class GitExporter: logging.debug(f"Committing {flat}") self.commit_flat(flat, branch_state) - self.git.push() + self.git.push(force=True) def run_gc(self): self.gc_cnt = self.gc_interval