From aa05df2e143675130bd959c5af82dcbd11a8f259 Mon Sep 17 00:00:00 2001 From: Mike Fedosin Date: Wed, 5 Oct 2022 17:45:26 +0200 Subject: [PATCH] Unify rebasing process This patch makes the process of rebasing similar to what we do manually. For instance, in https://github.com/openshift/kubernetes-autoscaler/pull/241 --- rebasebot/bot.py | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/rebasebot/bot.py b/rebasebot/bot.py index eb0d168..a0521b3 100755 --- a/rebasebot/bot.py +++ b/rebasebot/bot.py @@ -162,30 +162,12 @@ def _do_rebase(gitwd, source, dest, source_repo, tag_policy): raise RepoException(f"Git rebase failed: {ex}") from ex -def _needs_merge(gitwd, dest): - logging.info("Checking if we need a merge commit") - - try: - gitwd.git.checkout(f"dest/{dest.branch}") - gitwd.git.merge("--no-ff", "rebase") - except git.GitCommandError: - logging.info("Merge commit is required") - return True - finally: - gitwd.git.reset("--hard", "HEAD") - gitwd.git.checkout("rebase") - - logging.info("Merge commit is not required") - - return False - - def _do_merge(gitwd, dest): logging.info("Performing merge") try: gitwd.git.merge( - f"dest/{dest.branch}", "-Xours", "-m", - f"UPSTREAM: : Merge branch '{dest.branch}' in {gitwd.active_branch}" + f"dest/{dest.branch}", "-m", + f"merge branch '{dest.branch}' in {gitwd.active_branch}" ) except git.GitCommandError as ex: if not _resolve_conflict(gitwd): @@ -497,6 +479,8 @@ def run( return False try: + _do_merge(gitwd, dest) + needs_rebase = _needs_rebase(gitwd, source, dest) if needs_rebase: _do_rebase(gitwd, source, dest, source_repo, tag_policy) @@ -504,13 +488,6 @@ def run( if update_go_modules: _commit_go_mod_updates(gitwd, source) - # To prevent potential github conflicts we need to check if - # "git merge --no-ff" returns no errors. If it's not true, we - # have to create a merge commit. - needs_merge = _needs_merge(gitwd, dest) - if needs_merge: - _do_merge(gitwd, dest) - except RepoException as ex: logging.error(ex) _message_slack(