1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-04 03:48:07 +02:00

Add test for reverse-applying a patch that conflicts

The patch contains changes to two files; the first one conflicts, the second
doesn't. Note how it only applies changes to the first file at this point in the
branch; we'll fix this in the next commit.

This test would fail on master for multiple reasons.
This commit is contained in:
Stefan Haller 2023-02-25 21:00:29 +01:00
parent 6bd1c1d068
commit 4ca012dbfb
2 changed files with 92 additions and 0 deletions

View File

@ -0,0 +1,91 @@
package patch_building
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var ApplyInReverseWithConflict = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Apply a custom patch in reverse, resulting in a conflict",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("file1", "file1 content\n")
shell.CreateFileAndAdd("file2", "file2 content\n")
shell.Commit("first commit")
shell.UpdateFileAndAdd("file1", "file1 content\nmore file1 content\n")
shell.UpdateFileAndAdd("file2", "file2 content\nmore file2 content\n")
shell.Commit("second commit")
shell.UpdateFileAndAdd("file1", "file1 content\nmore file1 content\neven more file1\n")
shell.Commit("third commit")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("third commit").IsSelected(),
Contains("second commit"),
Contains("first commit"),
).
NavigateToLine(Contains("second commit")).
PressEnter()
t.Views().CommitFiles().
IsFocused().
Lines(
Contains("M").Contains("file1").IsSelected(),
Contains("M").Contains("file2"),
).
// Add both files to the patch; the first will conflict, the second won't
PressPrimaryAction().
SelectNextItem().
PressPrimaryAction()
t.Views().Information().Content(Contains("building patch"))
t.Views().PatchBuildingSecondary().Content(
Contains("+more file1 content").Contains("+more file2 content"))
t.Common().SelectPatchOption(Contains("apply patch in reverse"))
t.ExpectPopup().Alert().
Title(Equals("Error")).
Content(Contains("Applied patch to 'file1' with conflicts.").
DoesNotContain("Applied patch to 'file2' cleanly.")).
Confirm()
t.Views().Files().
Focus().
Lines(
Contains("UU").Contains("file1").IsSelected(),
).
PressPrimaryAction()
t.Views().MergeConflicts().
IsFocused().
ContainsLines(
Contains("file1 content"),
Contains("<<<<<<< ours").IsSelected(),
Contains("more file1 content").IsSelected(),
Contains("even more file1").IsSelected(),
Contains("=======").IsSelected(),
Contains(">>>>>>> theirs"),
).
SelectNextItem().
PressPrimaryAction()
t.Views().Files().
Focus().
Lines(
Contains("M").Contains("file1").IsSelected(),
)
t.Views().Main().
ContainsLines(
Contains(" file1 content"),
Contains("-more file1 content"),
Contains("-even more file1"),
)
},
})

View File

@ -99,6 +99,7 @@ var tests = []*components.IntegrationTest{
misc.InitialOpen,
patch_building.Apply,
patch_building.ApplyInReverse,
patch_building.ApplyInReverseWithConflict,
patch_building.CopyPatchToClipboard,
patch_building.MoveToIndex,
patch_building.MoveToIndexPartial,