Skip to content

Skip squashing with only one commit in a merge request

Stan Hu requested to merge sh-fix-squash-one-commit into master

We noticed in gitaly#2395 (closed) that the backend was unnecessarily attempting to squash merge requests with one commit. This happened because SquashService skips the squash if two conditions are met (https://gitlab.com/gitlab-org/gitlab/blob/563b27f41a032d79c5ce2afdf8db62ae8634329b/app/services/merge_requests/squash_service.rb#L8-12):

  1. The number of commits < 2
  2. The squash_commit_message is null

If a squash_commit_message is passed, this indicates that the user wants the squashed commit to have a different commit message.

By default, the frontend always sends squash_commit_message, regardless of whether the squash button is available in the merge request. With this change, the frontend will only send this parameter if the button is shown (i.e. when the commit count is >= 2).

Alternatively, we could also change the backend to skip squashing if only the first condition is met.

Closes #198971 (closed)

Edited by Stan Hu

Merge request reports