Skip to content

Commit

Permalink
Unify rebasing process
Browse files Browse the repository at this point in the history
This patch makes the process of rebasing similar to what we do manually.
For instance, in openshift/kubernetes-autoscaler#241
  • Loading branch information
Fedosin committed Oct 5, 2022
1 parent 9727bff commit aa05df2
Showing 1 changed file with 4 additions and 27 deletions.
31 changes: 4 additions & 27 deletions rebasebot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: <carry>: 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):
Expand Down Expand Up @@ -497,20 +479,15 @@ 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)

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(
Expand Down

0 comments on commit aa05df2

Please sign in to comment.