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).
This commit is contained in:
Stefan Haller 2026-05-21 21:18:19 +02:00
parent 98a421091f
commit c9eb915279
2 changed files with 30 additions and 0 deletions

View file

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

View file

@ -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}}",