gitlabgitlab-cicicdgitlab-runner

How does GitLab CI/CD determine if two branches can be merged?


For example, if the dev branch is behind the build branch when the two branches merge, the merge request can be created. But it is clear that it cannot merge because it is not possible to merge a backward branch into the current branch. In this case, I want to use the.gitlab-ci.yml configuration, To determine if the dev branch is behind the build branch, I wonder, can this be done? How to configure the.gitlab-ci.yml file if possible?


Solution

  • Basically, gitlab attempts the merge using git to determine if there's a conflict. It actually calls to gitaly to do this.

    Basically the process goes like this:

    1. The rails app in repository.rb will call to the gitaly conflict service to check for conclicts
    2. The conflict service list_conflict_file in gitaly will call to git2go
    3. The git2go conflicts subcommand will basically perform the git merge operation and return any conflicts that were encountered. This eventually makes its way back as a response to the call from rails in step (1)

    So, if you wanted to do something similar in your CI/CD pipeline, you could use git (or a programatic API to git in your favorite language) to attempt a local merge of the two branches in order to detect conflicts.