Skip to content

Commit cf27974

Browse files
committed
Add test for moving a commit across a branch boundary in a stack
The test demonstrates that the behavior is undesirable right now: we move the commit only past the update-ref todo of branch1, which means the order of commits stays the same and only the branch head icon moves up by one. However, we move the selection down by one, so the wrong commit is selected now. This is especially bad if you type a bunch of ctrl-j quickly in a row, because now you are moving the wrong commit. There are two possible ways to fix this: 1) keep the moving behavior the same, but don't change the selection 2) change the behavior so that we move the commit not only past the update-ref, but also past the next real commit. You could argue that 1) is the more desirable fix, as it gives you more control over where exactly the moved commit goes; however, it is much trickier to implement, so we go with 2) for now (and that's what the commented-out "EXPECTED" section documents here). If users need more fine-grained control, they can always enter an interactive rebase first.
1 parent 83356d4 commit cf27974

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 MoveAcrossBranchBoundaryOutsideRebase = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Move a commit across a branch boundary in a stack of branches",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
GitVersion: AtLeast("2.38.0"),
13+
SetupConfig: func(config *config.AppConfig) {
14+
config.GetUserConfig().Git.MainBranches = []string{"master"}
15+
config.GetAppState().GitLogShowGraph = "never"
16+
},
17+
SetupRepo: func(shell *Shell) {
18+
shell.
19+
CreateNCommits(1).
20+
NewBranch("branch1").
21+
CreateNCommitsStartingAt(2, 2).
22+
NewBranch("branch2").
23+
CreateNCommitsStartingAt(2, 4)
24+
25+
shell.SetConfig("rebase.updateRefs", "true")
26+
},
27+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
28+
t.Views().Commits().
29+
Focus().
30+
Lines(
31+
Contains("CI commit 05").IsSelected(),
32+
Contains("CI commit 04"),
33+
Contains("CI * commit 03"),
34+
Contains("CI commit 02"),
35+
Contains("CI commit 01"),
36+
).
37+
NavigateToLine(Contains("commit 04")).
38+
Press(keys.Commits.MoveDownCommit).
39+
Lines(
40+
/* EXPECTED:
41+
Contains("CI commit 05"),
42+
Contains("CI * commit 03"),
43+
Contains("CI commit 04").IsSelected(),
44+
Contains("CI commit 02"),
45+
Contains("CI commit 01"),
46+
ACTUAL: */
47+
Contains("CI commit 05"),
48+
Contains("CI * commit 04"),
49+
Contains("CI commit 03").IsSelected(),
50+
Contains("CI commit 02"),
51+
Contains("CI commit 01"),
52+
)
53+
},
54+
})

pkg/integration/tests/test_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ var tests = []*components.IntegrationTest{
223223
interactive_rebase.InteractiveRebaseOfCopiedBranch,
224224
interactive_rebase.MidRebaseRangeSelect,
225225
interactive_rebase.Move,
226+
interactive_rebase.MoveAcrossBranchBoundaryOutsideRebase,
226227
interactive_rebase.MoveInRebase,
227228
interactive_rebase.MoveUpdateRefTodo,
228229
interactive_rebase.MoveWithCustomCommentChar,

0 commit comments

Comments
 (0)