From 4ca012dbfbe0c6be33da36f442a4d7d10019fafd Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 25 Feb 2023 21:00:29 +0100 Subject: [PATCH] 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. --- .../apply_in_reverse_with_conflict.go | 91 +++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 2 files changed, 92 insertions(+) create mode 100644 pkg/integration/tests/patch_building/apply_in_reverse_with_conflict.go diff --git a/pkg/integration/tests/patch_building/apply_in_reverse_with_conflict.go b/pkg/integration/tests/patch_building/apply_in_reverse_with_conflict.go new file mode 100644 index 000000000..8c3e61a86 --- /dev/null +++ b/pkg/integration/tests/patch_building/apply_in_reverse_with_conflict.go @@ -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"), + ) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index dd1dfd70f..3a0fa8269 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -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,