From e1eb95b2b3492819d9732cae05bbf0e22f473914 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 31 Mar 2025 19:21:40 +0200 Subject: [PATCH] Add test for a special situation in rebases involving empty commits The situation is that you perform a rebase, and one of the commits becomes empty during the rebase, in a way that couldn't be predicted before the rebase started. To explain: git rebase has some logic where it immediately discards commits if it can tell that they already exist in the branch being rebased onto; it does this by looking at the patch ids of the commits to work out which commits already exist upstream. But for those commits that become empty even though there isn't a corresponding commit upstream, git stops with an error, and lazygit detects this (in CheckMergeOrRebaseWithRefreshOptions) and automatically continues the rebase. This all works fine; I'm adding this test because I almost broke this during development of this branch, so I'm adding it to guard against regressions. --- .../rebase_with_commit_that_becomes_empty.go | 45 +++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 2 files changed, 46 insertions(+) create mode 100644 pkg/integration/tests/interactive_rebase/rebase_with_commit_that_becomes_empty.go diff --git a/pkg/integration/tests/interactive_rebase/rebase_with_commit_that_becomes_empty.go b/pkg/integration/tests/interactive_rebase/rebase_with_commit_that_becomes_empty.go new file mode 100644 index 000000000..e9b743856 --- /dev/null +++ b/pkg/integration/tests/interactive_rebase/rebase_with_commit_that_becomes_empty.go @@ -0,0 +1,45 @@ +package interactive_rebase + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var RebaseWithCommitThatBecomesEmpty = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Performs a rebase involving a commit that becomes empty during the rebase, and gets dropped.", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.EmptyCommit("initial commit") + // It is important that we create two separate commits for the two + // changes to the file, but only one commit for the same changes on our + // branch; otherwise, the commit would be discarded at the start of the + // rebase already. + shell.CreateFileAndAdd("file", "change 1\n") + shell.Commit("master change 1") + shell.UpdateFileAndAdd("file", "change 1\nchange 2\n") + shell.Commit("master change 2") + shell.NewBranchFrom("branch", "HEAD^^") + shell.CreateFileAndAdd("file", "change 1\nchange 2\n") + shell.Commit("branch change") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Branches(). + Focus(). + NavigateToLine(Contains("master")). + Press(keys.Branches.RebaseBranch) + + t.ExpectPopup().Menu(). + Title(Equals("Rebase 'branch'")). + Select(Contains("Simple rebase")). + Confirm() + + t.Views().Commits(). + Lines( + Contains("master change 2"), + Contains("master change 1"), + Contains("initial commit"), + ) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index cbcf4ab5a..f381f8bea 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -260,6 +260,7 @@ var tests = []*components.IntegrationTest{ interactive_rebase.QuickStartKeepSelection, interactive_rebase.QuickStartKeepSelectionRange, interactive_rebase.Rebase, + interactive_rebase.RebaseWithCommitThatBecomesEmpty, interactive_rebase.RewordCommitWithEditorAndFail, interactive_rebase.RewordFirstCommit, interactive_rebase.RewordLastCommit,