This commit is contained in:
Arthur Albuquerque 2026-08-30 17:24:45 -07:00 committed by GitHub
commit c123d6c7e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 2 deletions

View file

@ -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
})
}

View 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)
}