From a7fcae2ca1ff66feacd45bcd236246177b0dc22b Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 7 Nov 2026 17:01:01 +0100 Subject: [PATCH] Add a test for squash merging while there are staged changes If the checked-out branch can be fast-forwarded to the selected branch, "git merge --squash" doesn't refuse to run while there are staged changes, unlike a merge that can't be fast-forwarded. It adds the changes of the branch to the ones that are already staged. "Squash merge and commit" then commits the staged changes along with the squashed ones, without the user noticing. Co-Authored-By: Claude Opus 5.5 --- .../squash_merge_with_staged_changes.go | 64 +++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 2 files changed, 65 insertions(+) create mode 100644 pkg/integration/tests/branch/squash_merge_with_staged_changes.go diff --git a/pkg/integration/tests/branch/squash_merge_with_staged_changes.go b/pkg/integration/tests/branch/squash_merge_with_staged_changes.go new file mode 100644 index 000000000..4778101b0 --- /dev/null +++ b/pkg/integration/tests/branch/squash_merge_with_staged_changes.go @@ -0,0 +1,64 @@ +package branch + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var SquashMergeWithStagedChanges = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Try to squash merge a branch while there are staged changes", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.NewBranch("original-branch"). + EmptyCommit("one"). + NewBranch("feature-branch"). + CreateFileAndAdd("feature-file", "content"). + Commit("feature"). + Checkout("original-branch"). + CreateFileAndAdd("staged-file", "content") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Branches(). + Focus(). + Lines( + Contains("original-branch").IsSelected(), + Contains("feature-branch"), + ). + SelectNextItem(). + Press(keys.Branches.MergeIntoCurrentBranch) + + t.ExpectPopup().Menu(). + Title(Equals("Merge")). + Select(Contains("Squash merge and commit")). + Confirm() + + /* EXPECTED: + t.ExpectToast(Equals("Disabled: Cannot squash merge while there are staged changes")) + + t.ExpectPopup().Menu(). + Title(Equals("Merge")). + Select(Contains("Squash merge and leave uncommitted")). + Confirm() + + t.ExpectToast(Equals("Disabled: Cannot squash merge while there are staged changes")) + ACTUAL: */ + t.Views().Commits(). + Focus(). + Lines( + Contains("Squash merge feature-branch into original-branch"), + Contains("one"), + ). + NavigateToLine(Contains("Squash merge feature-branch into original-branch")). + PressEnter() + + t.Views().CommitFiles(). + IsFocused(). + Lines( + Equals("▼ /"), + Contains("feature-file"), + Contains("staged-file"), + ) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index f2369036f..a20ab7f6b 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -110,6 +110,7 @@ var tests = []*components.IntegrationTest{ branch.SortRemoteBranches, branch.SortRemoteBranchesInStackOrder, branch.SquashMerge, + branch.SquashMergeWithStagedChanges, branch.Suggestions, branch.UnsetUpstream, cherry_pick.CherryPick,