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
squashparam is not provided: appliesproject.squash_enabled_by_default? - When
squashparam is explicitly provided (includingfalse): 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
- Create a project with
squash_optionset todefault_onoralways - Create an MR via API without the
squashparameter - Verify the MR has
squash: true