Skip to content

Commit e1eb95b

Browse files
committed
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.
1 parent b210b43 commit e1eb95b

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package interactive_rebase
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
var RebaseWithCommitThatBecomesEmpty = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Performs a rebase involving a commit that becomes empty during the rebase, and gets dropped.",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {},
13+
SetupRepo: func(shell *Shell) {
14+
shell.EmptyCommit("initial commit")
15+
// It is important that we create two separate commits for the two
16+
// changes to the file, but only one commit for the same changes on our
17+
// branch; otherwise, the commit would be discarded at the start of the
18+
// rebase already.
19+
shell.CreateFileAndAdd("file", "change 1\n")
20+
shell.Commit("master change 1")
21+
shell.UpdateFileAndAdd("file", "change 1\nchange 2\n")
22+
shell.Commit("master change 2")
23+
shell.NewBranchFrom("branch", "HEAD^^")
24+
shell.CreateFileAndAdd("file", "change 1\nchange 2\n")
25+
shell.Commit("branch change")
26+
},
27+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
28+
t.Views().Branches().
29+
Focus().
30+
NavigateToLine(Contains("master")).
31+
Press(keys.Branches.RebaseBranch)
32+
33+
t.ExpectPopup().Menu().
34+
Title(Equals("Rebase 'branch'")).
35+
Select(Contains("Simple rebase")).
36+
Confirm()
37+
38+
t.Views().Commits().
39+
Lines(
40+
Contains("master change 2"),
41+
Contains("master change 1"),
42+
Contains("initial commit"),
43+
)
44+
},
45+
})

pkg/integration/tests/test_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ var tests = []*components.IntegrationTest{
260260
interactive_rebase.QuickStartKeepSelection,
261261
interactive_rebase.QuickStartKeepSelectionRange,
262262
interactive_rebase.Rebase,
263+
interactive_rebase.RebaseWithCommitThatBecomesEmpty,
263264
interactive_rebase.RewordCommitWithEditorAndFail,
264265
interactive_rebase.RewordFirstCommit,
265266
interactive_rebase.RewordLastCommit,

0 commit comments

Comments
 (0)