smarkets / marge-bot

A merge-bot for GitLab
BSD 3-Clause "New" or "Revised" License
692 stars 136 forks source link

Add support for `--rebase-merges` during the rebase process #280

Open nicocvn opened 3 years ago

nicocvn commented 3 years ago

Summary

Add a configuration option to pass --rebase-merges for rebase operations.

Motivation

From the README:

  1. Marge-bot rebases the latest target branch (typically master) into the merge-request branch and pushes it. Once the tests have passed and there is a sufficient number of approvals (if a minimal approvals limit has been set on the project), Marge-bot will merge (or rebase, depending on project settings) the merge request via the GitLab API. It can also add some headers to all commits in the merge request as described in the next section.

What we observe in our projects is that this (as expected with git rebase) wipes out the merge commits.

Our typical workflow with branches is as follows:

Because of the rebase operation the merge commits are dropped and the release/x.y.z becomes a linear branch with all the commits from the various issue/xxx branches. This is not a show stopper but it would be great to have the option to preserve the structure of the branch.

The --rebase-merges option is specifically designed for this and was introduced in Git 2.18 (--preserve-merges seems to now be deprecated).

tclh123 commented 3 years ago

Hey, could you try this option --use-merge-strategy and see if that meets your requirements?

nicocvn commented 3 years ago

We actually did investigate that option but this was creating a merge commit on the source branch and then re-merging it onto the master branch which somewhat breaks our branching strategy.

Is this something you plan to support in the future? Or is there any interest in a PR?

I took a quick look at the code base and it seems that the rebase operation is controlled from here and initiated based on the strategy stored in the "fusion" options of the main app. I could try to make a proof of concept and see if I can make it work but I am a bit unclear on how you would prefer to expose that option (another strategy for rebasing/merging or a sub-option for the rebase strategy).

brettdh commented 3 years ago

I have an offline fork that implements this option; I'll try to put up a PR once I clear it with my employer.