From 9b88052a4e9d653effae9b5b49936e113b86c2ad Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 14 Jun 2024 13:23:12 +0200 Subject: [PATCH] Add test demonstrating problem with revert (or cherry-pick) during a rebase This problem can't happen inside of lazygit itself right now, but this will change in the future. It will only happen when you stopped in an interactive rebase on an "edit" entry, and then you perform a revert or cherry-pick consisting of more than one commit; in this situation lazygit will show a conflict although there is none. This is not possible with lazygit yet, as we don't support range-select for reverting, and we don't use `git cherry-pick` for cherry-picking. Both will change in the future, so it's good to fix this bug. --- ...vert_during_rebase_when_stopped_on_edit.go | 67 +++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 2 files changed, 68 insertions(+) create mode 100644 pkg/integration/tests/interactive_rebase/revert_during_rebase_when_stopped_on_edit.go diff --git a/pkg/integration/tests/interactive_rebase/revert_during_rebase_when_stopped_on_edit.go b/pkg/integration/tests/interactive_rebase/revert_during_rebase_when_stopped_on_edit.go new file mode 100644 index 000000000..a2138e874 --- /dev/null +++ b/pkg/integration/tests/interactive_rebase/revert_during_rebase_when_stopped_on_edit.go @@ -0,0 +1,67 @@ +package interactive_rebase + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var RevertDuringRebaseWhenStoppedOnEdit = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Revert a series of commits while stopped in a rebase", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(cfg *config.AppConfig) { + // TODO: use our revert UI once we support range-select for reverts + cfg.GetUserConfig().CustomCommands = []config.CustomCommand{ + { + Key: "X", + Context: "commits", + Command: "git -c core.editor=: revert HEAD^ HEAD^^", + }, + } + }, + SetupRepo: func(shell *Shell) { + shell.EmptyCommit("master commit") + shell.NewBranch("branch") + shell.CreateNCommits(4) + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + Focus(). + Lines( + Contains("commit 04").IsSelected(), + Contains("commit 03"), + Contains("commit 02"), + Contains("commit 01"), + Contains("master commit"), + ). + NavigateToLine(Contains("commit 03")). + Press(keys.Universal.Edit). + Lines( + Contains("pick").Contains("commit 04"), + Contains("<-- YOU ARE HERE --- commit 03").IsSelected(), + Contains("commit 02"), + Contains("commit 01"), + Contains("master commit"), + ). + Press("X"). + Lines( + /* EXPECTED: + Contains("pick").Contains("commit 04"), + Contains(`<-- YOU ARE HERE --- Revert "commit 01"`).IsSelected(), + Contains(`Revert "commit 02"`), + Contains("commit 03"), + Contains("commit 02"), + Contains("commit 01"), + Contains("master commit"), + ACTUAL: */ + Contains("pick").Contains("commit 04"), + Contains("edit").Contains("<-- CONFLICT --- commit 03").IsSelected(), + Contains(`Revert "commit 01"`), + Contains(`Revert "commit 02"`), + Contains("commit 03"), + Contains("commit 02"), + Contains("commit 01"), + Contains("master commit"), + ) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 7db3f55dd..ed051515f 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -264,6 +264,7 @@ var tests = []*components.IntegrationTest{ interactive_rebase.QuickStartKeepSelectionRange, interactive_rebase.Rebase, interactive_rebase.RebaseWithCommitThatBecomesEmpty, + interactive_rebase.RevertDuringRebaseWhenStoppedOnEdit, interactive_rebase.RevertMultipleCommitsInInteractiveRebase, interactive_rebase.RevertSingleCommitInInteractiveRebase, interactive_rebase.RewordCommitWithEditorAndFail,