diff --git a/pkg/gui/controllers/basic_commits_controller.go b/pkg/gui/controllers/basic_commits_controller.go index 47160080904..797215746c9 100644 --- a/pkg/gui/controllers/basic_commits_controller.go +++ b/pkg/gui/controllers/basic_commits_controller.go @@ -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. @@ -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 { diff --git a/pkg/gui/controllers/helpers/refs_helper.go b/pkg/gui/controllers/helpers/refs_helper.go index 6cb838e7f52..7b5374783a5 100644 --- a/pkg/gui/controllers/helpers/refs_helper.go +++ b/pkg/gui/controllers/helpers/refs_helper.go @@ -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 } @@ -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{