diff --git a/pkg/gui/controllers/helpers/base_branch_helper.go b/pkg/gui/controllers/helpers/base_branch_helper.go index e921ce93d..2386898a3 100644 --- a/pkg/gui/controllers/helpers/base_branch_helper.go +++ b/pkg/gui/controllers/helpers/base_branch_helper.go @@ -2,6 +2,9 @@ package helpers import ( "github.com/jesseduffield/lazygit/pkg/commands/models" + "github.com/jesseduffield/lazygit/pkg/gui/types" + "github.com/jesseduffield/lazygit/pkg/utils" + "github.com/samber/lo" ) // BaseBranchHelper resolves the base branch for a given branch. The @@ -35,3 +38,26 @@ func (self *BaseBranchHelper) ResolveBaseBranch(branch *models.Branch) (baseRef } return candidates[0], len(candidates) > 1, candidates, nil } + +// ShowPicker presents a menu of candidate base branches and runs +// onPicked with the user's selection. Callers should only invoke this +// when ResolveBaseBranch reported ambiguous=true; for the +// single-candidate case there is nothing to pick. +func (self *BaseBranchHelper) ShowPicker( + branch *models.Branch, + candidates []string, + onPicked func(baseRef string) error, +) error { + items := lo.Map(candidates, func(ref string, _ int) *types.MenuItem { + return &types.MenuItem{ + Label: ShortBranchName(ref), + OnPress: func() error { return onPicked(ref) }, + } + }) + return self.c.Menu(types.CreateMenuOptions{ + Title: utils.ResolvePlaceholderString(self.c.Tr.PickBaseBranchTitle, + map[string]string{"branchName": branch.Name}), + Prompt: self.c.Tr.PickBaseBranchPrompt, + Items: items, + }) +} diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index be3886fbe..e736481cc 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -563,6 +563,8 @@ type TranslationSet struct { ViewDivergenceFromUpstream string ViewDivergenceFromBaseBranch string CouldNotDetermineBaseBranch string + PickBaseBranchTitle string + PickBaseBranchPrompt string DivergenceSectionHeaderLocal string DivergenceSectionHeaderRemote string ViewUpstreamResetOptions string @@ -1715,6 +1717,8 @@ func EnglishTranslationSet() *TranslationSet { ViewDivergenceFromUpstream: "View divergence from upstream", ViewDivergenceFromBaseBranch: "View divergence from base branch ({{.baseBranch}})", CouldNotDetermineBaseBranch: "Couldn't determine base branch", + PickBaseBranchTitle: "Pick a base branch for {{.branchName}}", + PickBaseBranchPrompt: "More than one configured main branch is a candidate for this branch's base. Pick which one to treat as its base.", DivergenceSectionHeaderLocal: "Local", DivergenceSectionHeaderRemote: "Remote", ViewUpstreamResetOptions: "Reset checked-out branch onto {{.upstream}}",