Optimizing git multi-merge to master

59 views Asked by At

Given a collection of hashes for branch tips, is it possible to construct a tree of some sort to determine which tips are candidates for merging and which ones aren't with the current master of a project?

I'm not a CI/CD guy, but I'm trying to understand from a physics for poets standpoint if it's possible to construct a tree of some sort to determine which branches are eligible to be merged to master and which ones aren't.

Clarification

For the purposes of this query, the collection of branch tips in question are branches that 1) have no conflicts with master and 2) have passed all CI tests.

1

There are 1 answers

0
bk2204 On

What it sounds like you want is some sort of way to test mergeability. In general, this is hard with the command-line Git binary. You can attempt a test merge and run git merge --abort if it exits non-zero, but you are better off using libgit2 (or a wrapper in your preferred language) for this purpose, which provides the GIT_MERGE_FAIL_ON_CONFLICT flag which can be used to detect this case without modifying the repository.

As for checking with your CI or CD system to see if all the tests have passed, presumably it is possible. You haven't told us what system you're using, but many such systems have an API that you can use.

If you're using a Git hosting platform such as GitHub, you can query it for that state instead so you don't have to do it yourself. GitHub has documentation on how to check if a pull request is mergeable, and there's also a checks API you can use.