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 <noreply@anthropic.com>
This commit is contained in:
Stefan HallerandClaude Opus 5.5 committed 2026-11-08 15:36:41 +01:00
1 parent f2b182df45
commit a7fcae2ca1
2 files changed
+65

No files matched your search

@@ -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"),
)
},
})
+1
View File
@@ -110,6 +110,7 @@ var tests = []*components.IntegrationTest{
branch.SortRemoteBranches,
branch.SortRemoteBranchesInStackOrder,
branch.SquashMerge,
branch.SquashMergeWithStagedChanges,
branch.Suggestions,
branch.UnsetUpstream,
cherry_pick.CherryPick,