1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-06 22:33:07 +02:00

Add test for moving patch to index when there's a modified file

This is functionality that works already, we only add the test for more complete
test coverage. However, there's a detail problem, and the test demonstrates
this: we keep the stash even if there was no conflict. We'll fix this next.
This commit is contained in:
Stefan Haller
2025-07-01 12:57:16 +02:00
parent 00d043d743
commit 823aa640b9
2 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,64 @@
package patch_building
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var MoveToIndexWithModifiedFile = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Move a patch from a commit to the index, with a modified file in the working tree that conflicts with the patch",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("file1", "1\n2\n3\n4\n")
shell.Commit("first commit")
shell.UpdateFileAndAdd("file1", "11\n2\n3\n4\n")
shell.Commit("second commit")
shell.UpdateFile("file1", "111\n2\n3\n4\n")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("second commit").IsSelected(),
Contains("first commit"),
).
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Equals("M file1"),
).
PressPrimaryAction()
t.Views().Information().Content(Contains("Building patch"))
t.Views().Secondary().Content(Contains("-1\n+11"))
t.Common().SelectPatchOption(Contains("Move patch out into index"))
t.ExpectPopup().Confirmation().Title(Equals("Must stash")).
Content(Contains("Pulling a patch out into the index requires stashing and unstashing your changes.")).
Confirm()
t.Views().Files().
Focus().
Lines(
Equals("MM file1"),
)
t.Views().Main().
Content(Contains("-11\n+111\n"))
t.Views().Secondary().
Content(Contains("-1\n+11\n"))
/* EXPECTED:
t.Views().Stash().IsEmpty()
ACTUAL: */
t.Views().Stash().Lines(
Contains("Auto-stashing changes"),
)
},
})

View File

@ -310,6 +310,7 @@ var tests = []*components.IntegrationTest{
patch_building.MoveToIndexPartOfAdjacentAddedLines, patch_building.MoveToIndexPartOfAdjacentAddedLines,
patch_building.MoveToIndexPartial, patch_building.MoveToIndexPartial,
patch_building.MoveToIndexWithConflict, patch_building.MoveToIndexWithConflict,
patch_building.MoveToIndexWithModifiedFile,
patch_building.MoveToIndexWorksEvenIfNoprefixIsSet, patch_building.MoveToIndexWorksEvenIfNoprefixIsSet,
patch_building.MoveToLaterCommit, patch_building.MoveToLaterCommit,
patch_building.MoveToLaterCommitPartialHunk, patch_building.MoveToLaterCommitPartialHunk,