Skip to content

operations: Support worktreeless squashing for non-fast-forward merges

Patrick Steinhardt requested to merge pks-operations-squash-rebase into master

With 640b4de0 (operations: Implement squashing without worktrees, 2021-07-19), we have changed the implementation of UserSquash to support worktreeless squashing. The way this is implemented is that we simply take the tree of the end commit and the parents of the start commit, where the result is then the squashed commit. The initial assumption was that we're always going to have only fast-foward mergeable histories where the end commit is a direct descendant of the start commit. As it turned out, this assumption was wrong, which is why this implementation was special-cased in 0cbd9335 (operations: Squash via patches if commits are not directly related, 2021-07-20) to only apply for fast-forward mergeable commits.

With this change in place, we now only use worktreeless squashes in a subset of cases. We can generalize the current implementation though: if start and end commit do not have a direct parent-child relationship, then we must somehow update the child to be on top of the parent. This is exactly what rebases do: by rebasing the end commit on top of the start commit, we can again use above implement for non-fast-forward mergeable histories. And luckily, we already have in-memory-rebases which do not require worktrees via git2go.

This commit thus generalizes worktreeless squashing by always doing a rebase of the end commit on top of the start commit.

Closes #3690 (closed)

Merge request reports

Loading