Skip to content

Fix squash when target branch has a renamed file

Stan Hu requested to merge sh-fix-squash-renamed-files-target-branch into master

If a file were renamed on the target branch but the source branch still contained the original file, previously squash would fail with error: Sparse checkout leaves no entry on working directory. This happens because of the way a worktree is created with squash:

  1. git diff --name-only <START_SHA>...<END_SHA>, where START_SHA and END_SHA are from the source branch.
  2. This will populate info/sparse-checkout with the files changed on the source branch.
  3. We then checkout the target branch, which fails if all of the changed files from the source branch do not exist on it.

A squash should not be confused with a squash and rebase. Squash should simply take the existing commits on the branch and collapse them into one. The target branch is irrelevant, and so we should ignore the branch parameter entirely and use the source SHA.

Closes #2395 (closed)

Edited by GitLab Release Tools Bot

Merge request reports