From 1a76a7da094c346ee47cba6c3acfbd0ed6f60484 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 21 Jun 2024 19:16:54 +0200 Subject: Add test for moving a patch from an added file to an earlier commit This currently works (albeit with a bit of manual work, as the user needs to resolve conflicts), and we add this test just to make sure that we don't break it with the following change. --- .../move_to_earlier_commit_from_added_file.go | 115 +++++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 2 files changed, 116 insertions(+) create mode 100644 pkg/integration/tests/patch_building/move_to_earlier_commit_from_added_file.go (limited to 'pkg') diff --git a/pkg/integration/tests/patch_building/move_to_earlier_commit_from_added_file.go b/pkg/integration/tests/patch_building/move_to_earlier_commit_from_added_file.go new file mode 100644 index 000000000..122be3884 --- /dev/null +++ b/pkg/integration/tests/patch_building/move_to_earlier_commit_from_added_file.go @@ -0,0 +1,115 @@ +package patch_building + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var MoveToEarlierCommitFromAddedFile = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Move a patch from a file that was added in a commit to an earlier commit", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.EmptyCommit("first commit") + shell.EmptyCommit("destination commit") + shell.CreateFileAndAdd("file1", "1st line\n2nd line\n3rd line\n") + shell.Commit("commit to move from") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + Focus(). + Lines( + Contains("commit to move from").IsSelected(), + Contains("destination commit"), + Contains("first commit"), + ). + PressEnter() + + t.Views().CommitFiles(). + IsFocused(). + Lines( + Contains("A file").IsSelected(), + ). + PressEnter() + + t.Views().PatchBuilding(). + IsFocused(). + SelectNextItem(). + PressPrimaryAction() + + t.Views().Information().Content(Contains("Building patch")) + + t.Views().Commits(). + Focus(). + SelectNextItem() + + t.Common().SelectPatchOption(Contains("Move patch to selected commit")) + + // This results in a conflict at the commit we're moving from, because + // it tries to add a file that already exists + t.Common().AcknowledgeConflicts() + + t.Views().Files(). + IsFocused(). + Lines( + Contains("AA").Contains("file"), + ). + PressEnter() + + t.Views().MergeConflicts(). + IsFocused(). + TopLines( + Contains("<<<<<<< HEAD"), + Contains("2nd line"), + Contains("======="), + Contains("1st line"), + Contains("2nd line"), + Contains("3rd line"), + Contains(">>>>>>>"), + ). + SelectNextItem(). + PressPrimaryAction() // choose the version with all three lines + + t.Common().ContinueOnConflictsResolved() + + t.Views().Commits(). + Focus(). + Lines( + Contains("commit to move from"), + Contains("destination commit").IsSelected(), + Contains("first commit"), + ). + PressEnter() + + t.Views().CommitFiles(). + IsFocused(). + Lines( + Contains("A file").IsSelected(), + ). + Tap(func() { + t.Views().Main().ContainsLines( + Equals("+2nd line"), + ) + }). + PressEscape() + + t.Views().Commits(). + IsFocused(). + NavigateToLine(Contains("commit to move from")). + PressEnter() + + t.Views().CommitFiles(). + IsFocused(). + Lines( + Contains("M file").IsSelected(), + ). + Tap(func() { + t.Views().Main().ContainsLines( + Equals("+1st line"), + Equals(" 2nd line"), + Equals("+3rd line"), + ) + }) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 4ec3c4c6a..e2ca3721f 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -229,6 +229,7 @@ var tests = []*components.IntegrationTest{ patch_building.ApplyInReverseWithConflict, patch_building.MoveRangeToIndex, patch_building.MoveToEarlierCommit, + patch_building.MoveToEarlierCommitFromAddedFile, patch_building.MoveToEarlierCommitNoKeepEmpty, patch_building.MoveToIndex, patch_building.MoveToIndexPartOfAdjacentAddedLines, -- cgit v1.2.3