Apply project squash setting when creating MR via API

What does this MR do and why?

Fixes #385301

When creating a merge request via the REST API without explicitly providing the squash parameter, the project's squash_option setting is now respected. Previously, squash defaulted to false regardless of project configuration.

This aligns API behavior with the UI, which already respects project squash settings when creating merge requests.

Implementation Details

Change Summary

The fix is implemented in MergeRequests::CreateService#set_default_attributes!:

  • When squash param is not provided: applies project.squash_enabled_by_default?
  • When squash param is explicitly provided (including false): respects the explicit value

Why fix in CreateService (not API layer)?

Placing the fix in CreateService ensures all MR creation paths benefit:

  • REST API
  • GraphQL API
  • Push options (-o merge_request.create)
  • Any future creation paths

EE Consideration

Added super call in EE::MergeRequests::CreateService#set_default_attributes! to ensure the CE implementation runs. The EE override was not previously calling super, which was necessary since the CE method was empty. This change ensures both CE defaults (squash) and EE defaults (approval rules) are applied.

How to verify

  1. Create a project with squash_option set to default_on or always
  2. Create an MR via API without the squash parameter
  3. Verify the MR has squash: true

Merge request reports

Loading