migrate interactive rebase integration tests

This commit is contained in:
Jesse Duffield
2023-02-22 19:36:31 +11:00
parent 526c9dea9b
commit 78f3a7a478
353 changed files with 536 additions and 972 deletions

View File

@@ -95,17 +95,15 @@ func (self *RebaseCommands) GenericAmend(commits []*models.Commit, index int, f
}
func (self *RebaseCommands) MoveCommitDown(commits []*models.Commit, index int) error {
// we must ensure that we have at least two commits after the selected one
if len(commits) <= index+2 {
// assuming they aren't picking the bottom commit
return errors.New(self.Tr.NoRoom)
}
orderedCommits := append(commits[0:index], commits[index+1], commits[index])
// not appending to original slice so that we don't mutate it
orderedCommits := append([]*models.Commit{}, commits[0:index]...)
orderedCommits = append(orderedCommits, commits[index+1], commits[index])
todoLines := self.BuildTodoLinesSingleAction(orderedCommits, "pick")
return self.PrepareInteractiveRebaseCommand(commits[index+2].Sha, todoLines, true).Run()
baseShaOrRoot := getBaseShaOrRoot(commits, index+2)
return self.PrepareInteractiveRebaseCommand(baseShaOrRoot, todoLines, true).Run()
}
func (self *RebaseCommands) InteractiveRebase(commits []*models.Commit, index int, action string) error {
@@ -189,12 +187,9 @@ func (self *RebaseCommands) BuildSingleActionTodo(commits []*models.Commit, acti
}
})
baseSha := "--root"
if baseIndex < len(commits) {
baseSha = commits[baseIndex].Sha
}
baseShaOrRoot := getBaseShaOrRoot(commits, baseIndex)
return todoLines, baseSha, nil
return todoLines, baseShaOrRoot, nil
}
// AmendTo amends the given commit with whatever files are staged
@@ -418,3 +413,17 @@ func (self *TodoLine) ToString() string {
return self.Action + " " + self.Commit.Sha + " " + self.Commit.Name + "\n"
}
}
// we can't start an interactive rebase from the first commit without passing the
// '--root' arg
func getBaseShaOrRoot(commits []*models.Commit, index int) string {
// We assume that the commits slice contains the initial commit of the repo.
// Technically this assumption could prove false, but it's unlikely you'll
// be starting a rebase from 300 commits ago (which is the original commit limit
// at time of writing)
if index < len(commits) {
return commits[index].Sha
} else {
return "--root"
}
}

View File

@@ -358,6 +358,12 @@ func (self *LocalCommitsController) handleMidRebaseCommand(action string, commit
func (self *LocalCommitsController) moveDown(commit *models.Commit) error {
index := self.context().GetSelectedLineIdx()
commits := self.model.Commits
// can't move past the initial commit
if index >= len(commits)-1 {
return nil
}
if commit.Status == "rebasing" {
if commits[index+1].Status != "rebasing" {
return nil

View File

@@ -0,0 +1,84 @@
package interactive_rebase
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var Move = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Directly move a commit all the way down and all the way back up",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
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"),
).
Press(keys.Commits.MoveDownCommit).
Lines(
Contains("commit 03"),
Contains("commit 04").IsSelected(),
Contains("commit 02"),
Contains("commit 01"),
).
Press(keys.Commits.MoveDownCommit).
Lines(
Contains("commit 03"),
Contains("commit 02"),
Contains("commit 04").IsSelected(),
Contains("commit 01"),
).
Press(keys.Commits.MoveDownCommit).
Lines(
Contains("commit 03"),
Contains("commit 02"),
Contains("commit 01"),
Contains("commit 04").IsSelected(),
).
// assert nothing happens upon trying to move beyond the last commit
Press(keys.Commits.MoveDownCommit).
Lines(
Contains("commit 03"),
Contains("commit 02"),
Contains("commit 01"),
Contains("commit 04").IsSelected(),
).
Press(keys.Commits.MoveUpCommit).
Lines(
Contains("commit 03"),
Contains("commit 02"),
Contains("commit 04").IsSelected(),
Contains("commit 01"),
).
Press(keys.Commits.MoveUpCommit).
Lines(
Contains("commit 03"),
Contains("commit 04").IsSelected(),
Contains("commit 02"),
Contains("commit 01"),
).
Press(keys.Commits.MoveUpCommit).
Lines(
Contains("commit 04").IsSelected(),
Contains("commit 03"),
Contains("commit 02"),
Contains("commit 01"),
).
// assert nothing happens upon trying to move beyond the first commit
Press(keys.Commits.MoveUpCommit).
Lines(
Contains("commit 04").IsSelected(),
Contains("commit 03"),
Contains("commit 02"),
Contains("commit 01"),
)
},
})

View File

@@ -0,0 +1,96 @@
package interactive_rebase
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var MoveInRebase = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Via a single interactive rebase move a commit all the way up then back down then slightly back up again and apply the change",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
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"),
).
NavigateToListItem(Contains("commit 01")).
Press(keys.Universal.Edit).
Lines(
Contains("commit 04"),
Contains("commit 03"),
Contains("commit 02"),
Contains("YOU ARE HERE").Contains("commit 01").IsSelected(),
).
SelectPreviousItem().
Press(keys.Commits.MoveUpCommit).
Lines(
Contains("commit 04"),
Contains("commit 02").IsSelected(),
Contains("commit 03"),
Contains("YOU ARE HERE").Contains("commit 01"),
).
Press(keys.Commits.MoveUpCommit).
Lines(
Contains("commit 02").IsSelected(),
Contains("commit 04"),
Contains("commit 03"),
Contains("YOU ARE HERE").Contains("commit 01"),
).
Press(keys.Commits.MoveUpCommit).
// assert we can't move past the top
Lines(
Contains("commit 02").IsSelected(),
Contains("commit 04"),
Contains("commit 03"),
Contains("YOU ARE HERE").Contains("commit 01"),
).
Press(keys.Commits.MoveDownCommit).
Lines(
Contains("commit 04"),
Contains("commit 02").IsSelected(),
Contains("commit 03"),
Contains("YOU ARE HERE").Contains("commit 01"),
).
Press(keys.Commits.MoveDownCommit).
Lines(
Contains("commit 04"),
Contains("commit 03"),
Contains("commit 02").IsSelected(),
Contains("YOU ARE HERE").Contains("commit 01"),
).
// assert we can't move past the bottom
Press(keys.Commits.MoveDownCommit).
Lines(
Contains("commit 04"),
Contains("commit 03"),
Contains("commit 02").IsSelected(),
Contains("YOU ARE HERE").Contains("commit 01"),
).
// move it back up one so that we land in a different order than we started with
Press(keys.Commits.MoveUpCommit).
Lines(
Contains("commit 04"),
Contains("commit 02").IsSelected(),
Contains("commit 03"),
Contains("YOU ARE HERE").Contains("commit 01"),
).
Tap(func() {
t.Actions().ContinueRebase()
}).
Lines(
Contains("commit 04"),
Contains("commit 02").IsSelected(),
Contains("commit 03"),
DoesNotContain("YOU ARE HERE").Contains("commit 01"),
)
},
})

View File

@@ -1,71 +0,0 @@
package interactive_rebase
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var One = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Begins an interactive rebase, then fixups, drops, and squashes some commits",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.
CreateNCommits(5) // these will appears at commit 05, 04, 04, down to 01
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("commit 05"),
Contains("commit 04"),
Contains("commit 03"),
Contains("commit 02"),
Contains("commit 01"),
).
NavigateToListItem(Contains("commit 02")).
Press(keys.Universal.Edit).
Lines(
MatchesRegexp("pick.*commit 05"),
MatchesRegexp("pick.*commit 04"),
MatchesRegexp("pick.*commit 03"),
MatchesRegexp("YOU ARE HERE.*commit 02").IsSelected(),
Contains("commit 01"),
).
SelectPreviousItem().
Press(keys.Commits.MarkCommitAsFixup).
Lines(
MatchesRegexp("pick.*commit 05"),
MatchesRegexp("pick.*commit 04"),
MatchesRegexp("fixup.*commit 03").IsSelected(),
MatchesRegexp("YOU ARE HERE.*commit 02"),
Contains("commit 01"),
).
SelectPreviousItem().
Press(keys.Universal.Remove).
Lines(
MatchesRegexp("pick.*commit 05"),
MatchesRegexp("drop.*commit 04").IsSelected(),
MatchesRegexp("fixup.*commit 03"),
MatchesRegexp("YOU ARE HERE.*commit 02"),
Contains("commit 01"),
).
SelectPreviousItem().
Press(keys.Commits.SquashDown).
Lines(
MatchesRegexp("squash.*commit 05").IsSelected(),
MatchesRegexp("drop.*commit 04"),
MatchesRegexp("fixup.*commit 03"),
MatchesRegexp("YOU ARE HERE.*commit 02"),
Contains("commit 01"),
).
Tap(func() {
t.Actions().ContinueRebase()
}).
Lines(
Contains("commit 02"),
Contains("commit 01"),
)
},
})

View File

@@ -0,0 +1,122 @@
package interactive_rebase
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var Rebase = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Begins an interactive rebase, then fixups, drops, and squashes some commits",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.EmptyCommit("initial commit")
shell.EmptyCommit("first commit to edit")
shell.EmptyCommit("commit to squash")
shell.EmptyCommit("second commit to edit")
shell.EmptyCommit("commit to drop")
shell.CreateFileAndAdd("fixup-commit-file", "fixup-commit-file")
shell.Commit("commit to fixup")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("commit to fixup"),
Contains("commit to drop"),
Contains("second commit to edit"),
Contains("commit to squash"),
Contains("first commit to edit"),
Contains("initial commit"),
).
NavigateToListItem(Contains("first commit to edit")).
Press(keys.Universal.Edit).
Lines(
MatchesRegexp("pick.*commit to fixup"),
MatchesRegexp("pick.*commit to drop"),
MatchesRegexp("pick.*second commit to edit"),
MatchesRegexp("pick.*commit to squash"),
MatchesRegexp("YOU ARE HERE.*first commit to edit").IsSelected(),
Contains("initial commit"),
).
SelectPreviousItem().
Press(keys.Commits.SquashDown).
Lines(
MatchesRegexp("pick.*commit to fixup"),
MatchesRegexp("pick.*commit to drop"),
MatchesRegexp("pick.*second commit to edit"),
MatchesRegexp("squash.*commit to squash").IsSelected(),
MatchesRegexp("YOU ARE HERE.*first commit to edit"),
Contains("initial commit"),
).
SelectPreviousItem().
Press(keys.Universal.Edit).
Lines(
MatchesRegexp("pick.*commit to fixup"),
MatchesRegexp("pick.*commit to drop"),
MatchesRegexp("edit.*second commit to edit").IsSelected(),
MatchesRegexp("squash.*commit to squash"),
MatchesRegexp("YOU ARE HERE.*first commit to edit"),
Contains("initial commit"),
).
SelectPreviousItem().
Press(keys.Universal.Remove).
Lines(
MatchesRegexp("pick.*commit to fixup"),
MatchesRegexp("drop.*commit to drop").IsSelected(),
MatchesRegexp("edit.*second commit to edit"),
MatchesRegexp("squash.*commit to squash"),
MatchesRegexp("YOU ARE HERE.*first commit to edit"),
Contains("initial commit"),
).
SelectPreviousItem().
Press(keys.Commits.MarkCommitAsFixup).
Lines(
MatchesRegexp("fixup.*commit to fixup").IsSelected(),
MatchesRegexp("drop.*commit to drop"),
MatchesRegexp("edit.*second commit to edit"),
MatchesRegexp("squash.*commit to squash"),
MatchesRegexp("YOU ARE HERE.*first commit to edit"),
Contains("initial commit"),
).
Tap(func() {
t.Actions().ContinueRebase()
}).
Lines(
MatchesRegexp("fixup.*commit to fixup").IsSelected(),
MatchesRegexp("drop.*commit to drop"),
MatchesRegexp("YOU ARE HERE.*second commit to edit"),
MatchesRegexp("first commit to edit"),
Contains("initial commit"),
).
Tap(func() {
t.Actions().ContinueRebase()
}).
Lines(
Contains("second commit to edit").IsSelected(),
Contains("first commit to edit"),
Contains("initial commit"),
).
Tap(func() {
// commit 4 was squashed into 6 so we assert that their messages have been concatenated
t.Views().Main().Content(
Contains("second commit to edit").
// file from fixup commit is present
Contains("fixup-commit-file").
// but message is not (because it's a fixup, not a squash)
DoesNotContain("commit to fixup"),
)
}).
SelectNextItem().
Tap(func() {
// commit 4 was squashed into 6 so we assert that their messages have been concatenated
t.Views().Main().Content(
Contains("first commit to edit").
// message from squashed commit has been concatenated with message other commit
Contains("commit to squash"),
)
})
},
})

View File

@@ -5,6 +5,9 @@ import (
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
// Rewording the first commit is tricky because you can't rebase from its parent commit,
// hence having a specific test for this
var RewordFirstCommit = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Rewords the first commit, just to show that it's possible",
ExtraCmdArgs: "",

View File

@@ -0,0 +1,38 @@
package interactive_rebase
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var RewordLastCommit = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Rewords the last (HEAD) commit",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.
CreateNCommits(2)
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("commit 02").IsSelected(),
Contains("commit 01"),
).
Press(keys.Commits.RenameCommit).
Tap(func() {
t.ExpectPopup().Prompt().
Title(Equals("reword commit")).
InitialText(Equals("commit 02")).
Clear().
Type("renamed 02").
Confirm()
}).
Lines(
Contains("renamed 02"),
Contains("commit 01"),
)
},
})

View File

@@ -0,0 +1,126 @@
package interactive_rebase
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var SwapInRebaseWithConflict = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Via an edit-triggered rebase, swap two commits, causing a conflict. Then resolve the conflict and continue",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("myfile", "one")
shell.Commit("commit one")
shell.UpdateFileAndAdd("myfile", "two")
shell.Commit("commit two")
shell.UpdateFileAndAdd("myfile", "three")
shell.Commit("commit three")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("commit three").IsSelected(),
Contains("commit two"),
Contains("commit one"),
).
NavigateToListItem(Contains("commit one")).
Press(keys.Universal.Edit).
Lines(
Contains("commit three"),
Contains("commit two"),
Contains("YOU ARE HERE").Contains("commit one").IsSelected(),
).
SelectPreviousItem().
Press(keys.Commits.MoveUpCommit).
Lines(
Contains("commit two").IsSelected(),
Contains("commit three"),
Contains("YOU ARE HERE").Contains("commit one"),
).
Tap(func() {
t.Actions().ContinueRebase()
})
handleConflictsFromSwap(t)
},
})
func handleConflictsFromSwap(t *TestDriver) {
continueMerge := func() {
t.ExpectPopup().Confirmation().
Title(Equals("continue")).
Content(Contains("all merge conflicts resolved. Continue?")).
Confirm()
}
acceptConflicts := func() {
t.ExpectPopup().Confirmation().
Title(Equals("Auto-merge failed")).
Content(Contains("Conflicts!")).
Confirm()
}
acceptConflicts()
t.Views().Files().
IsFocused().
Lines(
Contains("UU myfile"),
).
PressEnter()
t.Views().MergeConflicts().
IsFocused().
TopLines(
Contains("<<<<<<< HEAD"),
Contains("one"),
Contains("======="),
Contains("three"),
Contains(">>>>>>>"),
).
SelectNextItem().
PressPrimaryAction() // pick "three"
continueMerge()
acceptConflicts()
t.Views().Files().
IsFocused().
Lines(
Contains("UU myfile"),
).
PressEnter()
t.Views().MergeConflicts().
IsFocused().
TopLines(
Contains("<<<<<<< HEAD"),
Contains("three"),
Contains("======="),
Contains("two"),
Contains(">>>>>>>"),
).
SelectNextItem().
PressPrimaryAction() // pick "two"
continueMerge()
t.Views().Commits().
Focus().
Lines(
Contains("commit two").IsSelected(),
Contains("commit three"),
Contains("commit one"),
).
Tap(func() {
t.Views().Main().Content(Contains("-three").Contains("+two"))
}).
SelectNextItem().
Tap(func() {
t.Views().Main().Content(Contains("-one").Contains("+three"))
})
}

View File

@@ -0,0 +1,33 @@
package interactive_rebase
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var SwapWithConflict = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Directly swap two commits, causing a conflict. Then resolve the conflict and continue",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("myfile", "one")
shell.Commit("commit one")
shell.UpdateFileAndAdd("myfile", "two")
shell.Commit("commit two")
shell.UpdateFileAndAdd("myfile", "three")
shell.Commit("commit three")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("commit three").IsSelected(),
Contains("commit two"),
Contains("commit one"),
).
Press(keys.Commits.MoveDownCommit)
handleConflictsFromSwap(t)
},
})

View File

@@ -74,11 +74,16 @@ var tests = []*components.IntegrationTest{
interactive_rebase.EditFirstCommit,
interactive_rebase.FixupFirstCommit,
interactive_rebase.FixupSecondCommit,
interactive_rebase.One,
interactive_rebase.Move,
interactive_rebase.MoveInRebase,
interactive_rebase.Rebase,
interactive_rebase.RewordFirstCommit,
interactive_rebase.RewordLastCommit,
interactive_rebase.SquashDownFirstCommit,
interactive_rebase.SquashDownSecondCommit,
interactive_rebase.SquashFixupsAboveFirstCommit,
interactive_rebase.SwapInRebaseWithConflict,
interactive_rebase.SwapWithConflict,
misc.ConfirmOnQuit,
misc.InitialOpen,
patch_building.CopyPatchToClipboard,