mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 15:46:26 -04:00
fix: guard against nil remote branch pointers in display strings
During concurrent remote refresh, stale nil pointers can appear in the branches slice, causing a panic in GetRemoteBranchListDisplayStrings when branch.FullName() is called. Skip nil entries with lo.FilterMap instead of lo.Map. Fixes #5370
This commit is contained in:
parent
353e3a1e4a
commit
b1cef59a89
|
|
@ -8,9 +8,12 @@ import (
|
|||
)
|
||||
|
||||
func GetRemoteBranchListDisplayStrings(branches []*models.RemoteBranch, diffName string) [][]string {
|
||||
return lo.Map(branches, func(branch *models.RemoteBranch, _ int) []string {
|
||||
return lo.FilterMap(branches, func(branch *models.RemoteBranch, _ int) ([]string, bool) {
|
||||
if branch == nil {
|
||||
return nil, false
|
||||
}
|
||||
diffed := branch.FullName() == diffName
|
||||
return getRemoteBranchDisplayStrings(branch, diffed)
|
||||
return getRemoteBranchDisplayStrings(branch, diffed), true
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
18
pkg/gui/presentation/remote_branches_test.go
Normal file
18
pkg/gui/presentation/remote_branches_test.go
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package presentation
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetRemoteBranchListDisplayStrings_NilBranch(t *testing.T) {
|
||||
branch := &models.RemoteBranch{Name: "main", RemoteName: "origin"}
|
||||
branches := []*models.RemoteBranch{nil, branch, nil}
|
||||
|
||||
result := GetRemoteBranchListDisplayStrings(branches, "")
|
||||
|
||||
// nil entries must be skipped; only the valid branch produces a row
|
||||
assert.Len(t, result, 1)
|
||||
}
|
||||
Loading…
Reference in a new issue