Skip to content

Allow squashing in MRs with single commit

What does this MR do and why?

This MR allows squashing merge requests with single commit and solves #339743 (closed), #346005 (closed) and should also resolve #219747 (closed).

Currently for Merge Requests with only one commit, squash is not performed, even if the project enforces it in settings. If squash isn't enforced, the squash checkbox is not shown at all in merge widget for MRs with only one commit.

I propose this change as a prerequisite for my other MR, !74340 (merged). That linked MR adds squash commit message template, similar to the recently added merge commit message template. Without change proposed in this MR, template would not have any effect in MRs with single commit. That means that for projects enforcing squash with ff merge enabled, neither squash nor merge commit message template would apply for MRs with one commit.

This issue was brought up by two users independently in my previous MR for merge commit message templates: !64437 (comment 727111515) and !64437 (comment 686755486). It was also mentioned in comment #330646 (comment 694844867).

Reading through the original issue for adding squash commits ( #150 (closed) ) it looks like there wasn't any discussion on this case - it was simply stated that This checkbox is only when accepting if there is more than one commit in the MR - otherwise, there's nothing to squash..

I feel like current gitlab's behavior is confusing, and that's why I'm proposing this change.

I've tried to retain what was possible of optimization added in !23744 (merged) by not performing squash when there's only one commit and the message remains the same.

Screenshots or screen recordings

For MR with 1 commit in project with FF merge enbaled, and enforced squash:

Before

image

The image above shows current state, before my changes. In this case, there's no way to customize message, and commit message would be left unchanged.

After

image

Here, squash is performed normally, changing commit message to new one that can be customized. Squash commit message template would apply.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

This change:

  • Allows checking "Squash commits" in MRs with 1 commit for projects with allowed/encouraged squash.
  • Performs squash when merging MR for projects with enforced squash in MRs with 1 commit.
  • Skips performing squash only when there's 1 commit in MR and squash commit message is the same as existing commit message. When no message is passed, it's compared to default squash commit message.

Changelog: changed

Edited by Piotr Stankowski

Merge request reports