Refactor merge script into classes, don't require rebase #3276
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
In #3263 we created a Python script to merge pull requests more easily.
Motivation
The script is very procedurally-oriented; it's one long function containing a sequence of complex steps that aren't always clearly related to one another, and not much structure or abstraction. This makes it harder to isolate one particular operation and check that it works properly.
Problem
The script seems unable to merge branches that aren't rebased on current master, even if the conflicts are trivial. It is inconvenient to have to rebase every pull request before merging.
Cause
repo.index.merge_tree
doesn't do well with conflicts, but it's what you'll find if you go looking for ways to merge with GitPython. I think it is intended to be a low-level tool for apps that intend to re-implement parts of thegit merge
command themselves differently. That's not us; we just want the regular merge command.Changes
CkanRepo
represents the repo on disk and handles common operations such as checking if the master is up to date or editing files or knowing where the change log isCkanPullRequest
represents a pull request and handles other operations such as getting the change log entry and commit message and doing the actual mergerepo.git.merge
, which handles trivial conflicts better, andrepo.git.commit
, which is needed when the merge is started withrepo.git.merge
. These are simple wrappers around thegit merge
andgit commit
commands, so we can be more sure they'll be similar to the old commands.Multiple
for multiple andUNKNOWN
for none, to be filled in by the user