Configurable defaults for "Squash commits" option
Problem to solve
Squashing commits in Git in a great way to merge several commits into one with the powerful interactive rebase. It's great for grouping several small commits into a single large commit before pushing upstream. However, because squashing rewrites repository history and loses some granularity, it is not favored by all as the default option.
In GitLab 13.3 we are adding configurable defaults for squashing commits, allowing project maintainers to configure the option to suit their preferred workflow.
Further Details
- Implementation MR: !33827 (merged)
- FF for rollout: #232536 (closed)
- Documentation: https://docs.gitlab.com/ee/user/project/merge_requests/squash_and_merge.html#squash-commits-options
Squash and merge is a very useful feature, but is polarizing. Some teams it is the way every merge request should be handled, while other teams want it completely disabled because it would cause serious problems for their branching strategy, and many are happy to leave it up to the developer who creates the merge request. GitLab should make squash and merge a configurable option.
Original request from @davidarcher:
We love the new squash merge feature in GitLab and have updated our team's process documentation to tell devs to use it on every MR. However, they need to remember to check the box on every MR. It would be great if we could enforce this at the project level instead of relying on devs checking it on each and every MR.
Opposite request from @neemo157 on https://gitlab.com/gitlab-org/gitlab-ce/issues/49046:
This feature is super-useful and we use it in a lot of our repositories. However, we have at least 1 repository where we want to be very careful about maintaining history between a pair of branches, when we merge across from one to the other we have to keep the exact same commits to keep the history working correctly. Since we use this feature in other repositories it's far too tempting for our developers to press it all the time, which results in a new commit being created diverging the branches histories.
Proposal
- Add a drop down to to the project settings page Squashing commits before merging with the options
-
Never
(do not show the squash option, do not squash) -
Allowed
(default, current behavior, show the squash option, unchecked but user can enable) -
Enabled
(show the squash option, checked but user can disable) -
Always
(show the squash option, check and the user cannot disable)
-
Testing
- As noted, we'll want to add tests (including feature specs) to cover existing work and any adjustments we need to make.
- There is an end-to-end test covering the Squash feature, however it only covers the default merge method so this would be a good opportunity for an SET to add end-to-end coverage of the other project merge method options.
-
Please run package-and-qa
to confirm that the existing test passes.