From c9eb9152794fea14740e9e07380e2a77b594e4aa Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 21 May 2026 21:18:19 +0200 Subject: [PATCH] Add disambiguation menu to BaseBranchHelper When ResolveBaseBranch reports a tie, callers need a way to ask the user which of the configured main branches to use as the base. ShowPicker takes the candidate list and a continuation, presents a menu of short branch names, and runs the continuation with the user's selection. Subsequent commits wire this into the three GUI actions that care (rebase-onto-base, view-divergence, move-commits). --- .../controllers/helpers/base_branch_helper.go | 26 +++++++++++++++++++ pkg/i18n/english.go | 4 +++ 2 files changed, 30 insertions(+) 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}}",