Skip to content

Clarify what #cannot_be_merged? == true means

What does this MR do and why?

:cannot_be_merged is a state in MergeRequests state machine that is generally indicative of conflicts, however it can be set to true by other conditions that render the MR unmergeable. As a state, it is entered by a :mark_as_unmergeable event. There's 2 locations we currently trigger this, both in MergeRequests::MergeabilityCheckService, and they boil down to either of these 2 conditions:

  • any of these are true
    • #has_no_commits?
    • #branch_missing?
    • #cannot_be_merged?
  • either of these occur
    • MergeRequests::MergeToRefService returns an error
    • #can_git_merge? is false

As an example:

# from app/models/merge_request.rb
#
  def has_commits?
    merge_request_diff.persisted? && commits_count.to_i > 0
  end

  def has_no_commits?
    !has_commits?
  end

..so you see, it's indicative of more than just "there's a conflict", but that's our messaging. In this MR, we update an error message that has caused some customer confusion (thinking there was a conflict when the issue was an empty MR..), update API docs, and sprinkle in some code comments for additional context or a future cleanup effort.

Merge request reports