Skip to content

Commit

Permalink
Move branch filtering into helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Flügge committed Dec 25, 2024
1 parent a784170 commit 32dab41
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
7 changes: 1 addition & 6 deletions pkg/gui/controllers/basic_commits_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/samber/lo"
)

// This controller is for all contexts that contain a list of commits.
Expand Down Expand Up @@ -281,11 +280,7 @@ func (self *BasicCommitsController) createResetMenu(commit *models.Commit) error
}

func (self *BasicCommitsController) checkout(commit *models.Commit) error {
commitBranches := lo.Filter(self.c.Model().Branches, func(branch *models.Branch, _ int) bool {
return commit.Hash == branch.CommitHash && branch.Name != self.c.Model().CheckedOutBranch
})

return self.c.Helpers().Refs.CreateCheckoutMenu(commit.Hash, commitBranches)
return self.c.Helpers().Refs.CreateCheckoutMenu(commit)
}

func (self *BasicCommitsController) copyRange(*models.Commit) error {
Expand Down
9 changes: 7 additions & 2 deletions pkg/gui/controllers/helpers/refs_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type IRefsHelper interface {
CheckoutRef(ref string, options types.CheckoutRefOptions) error
GetCheckedOutRef() *models.Branch
CreateGitResetMenu(ref string) error
CreateCheckoutMenu(ref string, branches []*models.Branch) error
CreateCheckoutMenu(commit *models.Commit) error
ResetToRef(ref string, strength string, envVars []string) error
NewBranch(from string, fromDescription string, suggestedBranchname string) error
}
Expand Down Expand Up @@ -272,7 +272,12 @@ func (self *RefsHelper) CreateGitResetMenu(ref string) error {
})
}

func (self *RefsHelper) CreateCheckoutMenu(ref string, branches []*models.Branch) error {
func (self *RefsHelper) CreateCheckoutMenu(commit *models.Commit) error {
branches := lo.Filter(self.c.Model().Branches, func(branch *models.Branch, _ int) bool {
return commit.Hash == branch.CommitHash && branch.Name != self.c.Model().CheckedOutBranch
})

ref := commit.Hash
var menuItems []*types.MenuItem

menuItems = append(menuItems, &types.MenuItem{
Expand Down

0 comments on commit 32dab41

Please sign in to comment.