Skip to content

"Branch cannot be modified" errors when adjust the auto-merge attribute via the API

Summary

"Branch cannot be merged" error is shown in a very specific situation when setting it via the API after cancelled. Steps below.

Steps to reproduce

  1. Create a new project, create an issue and a respective MR
  2. Use the API or UI to set the merge_after to a future date and time.
  3. In the MR, add a CI job. Run a pipeline for the branch the MR is for.
  4. While the pipeline is running, use the API to set auto_merge. The request will succeed.
  5. Cancel auto_merge via the API, add another change, wait for the pipeline to succeed.
  6. After the pipeline has succeeded, use the API to set auto_merge. The request will fail with the message Branch cannot be merged.
  7. Also in the UI Merge request is not mergeable. Try again error is shown.
  8. But if we attempt to set the auto-merge via the UI, this succeeds.

Some observations:

  • when the pipeline is still running, the MR attribute merge_when_pipeline_succeeds is set to true
  • when the pipeline has succeeded, the MR attribute merge_when_pipeline_succeeds is set to false

Setting the value for merge_when_pipeline_succeeds (deprecated, but done for testing) to true to be shown the same Branch cannot be merged error.

Example Project

https://gitlab.com/ndesilva-gold/ticket-testing/621665/-/merge_requests/4

What is the current bug behavior?

Branch cannot be merged error is shown for the API call.

What is the expected correct behavior?

MR set to auto-merge as expected to reflect UI behavior.

Relevant logs and/or screenshots

Output of checks

This bug happens on GitLab.com and self-managed instances.

Results of GitLab environment info

Expand for output related to GitLab environment info

  (For installations with omnibus-gitlab package run and paste the output of: \\\`sudo gitlab-rake gitlab:env:info\\\`)  (For installations from source run and paste the output of: \\\`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production\\\`)   

Results of GitLab application Check

Expand for output related to the GitLab application check

 (For installations with omnibus-gitlab package run and paste the output of: \`sudo gitlab-rake gitlab:check SANITIZE=true\`)  (For installations from source run and paste the output of: \`sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true\`)  (we will only investigate if the tests are passing)  

Possible fixes

Patch release information for backports

If the bug fix needs to be backported in a patch release to a version under the maintenance policy, please follow the steps on the patch release runbook for GitLab engineers.

Refer to the internal "Release Information" dashboard for information about the next patch release, including the targeted versions, expected release date, and current status.

High-severity bug remediation

To remediate high-severity issues requiring an internal release for single-tenant SaaS instances, refer to the internal release process for engineers.

Edited by 🤖 GitLab Bot 🤖