From b02441cdca967feaad66a84b0d1f4ced357e31cf Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 10 May 2025 15:05:38 +0200 Subject: [PATCH] Regression test for moving custom patch to new commit from last commit of a stacked branch I almost broke this during the development of this branch, so add a test to guard against that. The point here is that the stack remains intact, i.e. the newly created commit is the last commit of the lower branch, and thus shows the "*". --- ...commit_in_last_commit_of_stacked_branch.go | 72 +++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 2 files changed, 73 insertions(+) create mode 100644 pkg/integration/tests/patch_building/move_to_new_commit_in_last_commit_of_stacked_branch.go diff --git a/pkg/integration/tests/patch_building/move_to_new_commit_in_last_commit_of_stacked_branch.go b/pkg/integration/tests/patch_building/move_to_new_commit_in_last_commit_of_stacked_branch.go new file mode 100644 index 000000000..645d2a120 --- /dev/null +++ b/pkg/integration/tests/patch_building/move_to_new_commit_in_last_commit_of_stacked_branch.go @@ -0,0 +1,72 @@ +package patch_building + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var MoveToNewCommitInLastCommitOfStackedBranch = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Move a patch from a commit to a new commit, in the last commit of a branch in the middle of a stack", + ExtraCmdArgs: []string{}, + Skip: false, + GitVersion: AtLeast("2.38.0"), + SetupConfig: func(config *config.AppConfig) { + config.GetAppState().GitLogShowGraph = "never" + }, + SetupRepo: func(shell *Shell) { + shell. + EmptyCommit("commit 01"). + NewBranch("branch1"). + EmptyCommit("commit 02"). + CreateFileAndAdd("file1", "file1 content"). + CreateFileAndAdd("file2", "file2 content"). + Commit("commit 03"). + NewBranch("branch2"). + CreateNCommitsStartingAt(2, 4) + + shell.SetConfig("rebase.updateRefs", "true") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + Focus(). + Lines( + Contains("CI commit 05").IsSelected(), + Contains("CI commit 04"), + Contains("CI * commit 03"), + Contains("CI commit 02"), + Contains("CI commit 01"), + ). + NavigateToLine(Contains("commit 03")). + PressEnter() + + t.Views().CommitFiles(). + IsFocused(). + Lines( + Equals("▼ /").IsSelected(), + Equals(" A file1"), + Equals(" A file2"), + ). + SelectNextItem(). + PressPrimaryAction(). + PressEscape() + + t.Views().Information().Content(Contains("Building patch")) + + t.Common().SelectPatchOption(Contains("Move patch into new commit")) + + t.ExpectPopup().CommitMessagePanel(). + InitialText(Equals("")). + Type("new commit").Confirm() + + t.Views().Commits(). + IsFocused(). + Lines( + Contains("CI commit 05"), + Contains("CI commit 04"), + Contains("CI * new commit").IsSelected(), + Contains("CI commit 03"), + Contains("CI commit 02"), + Contains("CI commit 01"), + ) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 26d02cd76..6093a387a 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -311,6 +311,7 @@ var tests = []*components.IntegrationTest{ patch_building.MoveToNewCommit, patch_building.MoveToNewCommitFromAddedFile, patch_building.MoveToNewCommitFromDeletedFile, + patch_building.MoveToNewCommitInLastCommitOfStackedBranch, patch_building.MoveToNewCommitPartialHunk, patch_building.RemoveFromCommit, patch_building.RemovePartsOfAddedFile,