1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-05-17 22:32:58 +02:00

fix panic on rebase

This commit is contained in:
Jesse Duffield 2022-01-24 19:42:40 +11:00
parent 5e6e1617aa
commit ebbdf829e7
2 changed files with 47 additions and 20 deletions

View File

@ -50,10 +50,9 @@ func GetCommitListDisplayStrings(
return nil
}
// this is where my non-TODO commits begin
rebaseOffset := indexOfFirstNonTODOCommit(commits)
end := utils.Min(startIdx+length, len(commits))
// this is where my non-TODO commits begin
rebaseOffset := utils.Min(indexOfFirstNonTODOCommit(commits), end)
filteredCommits := commits[startIdx:end]

View File

@ -34,6 +34,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
showGraph bool
bisectInfo *git_commands.BisectInfo
expected string
focus bool
}{
{
testName: "no commits",
@ -174,10 +175,36 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
sha5 commit5
`),
},
{
testName: "only TODO commits except last",
commits: []*models.Commit{
{Name: "commit1", Sha: "sha1", Parents: []string{"sha2", "sha3"}, Action: "pick"},
{Name: "commit2", Sha: "sha2", Parents: []string{"sha3"}, Action: "pick"},
{Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}, Action: "pick"},
{Name: "commit4", Sha: "sha4", Parents: []string{"sha5"}, Action: "pick"},
{Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}},
},
startIdx: 0,
length: 2,
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
expected: formatExpected(`
sha1 pick commit1
sha2 pick commit2
`),
},
}
focusing := false
for _, scenario := range scenarios {
if scenario.focus {
focusing = true
}
}
for _, s := range scenarios {
s := s
if !focusing || s.focus {
t.Run(s.testName, func(t *testing.T) {
result := GetCommitListDisplayStrings(
s.commits,
@ -199,3 +226,4 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
})
}
}
}