Route base-branch lookups through the shared resolver

The four call sites that need a single base branch (legacy
behind-base loader, view-divergence menu, rebase-onto-base action,
move-commits-to-new-branch) now go through BaseBranchHelper.ResolveBaseBranch
in the GUI sites, and directly take candidates[0] in the loader. They
all use the same config-order tiebreak. No prompt yet — the helper
still returns the config-order first for ambiguous cases; subsequent
commits add the disambiguation menu.

MergeAndRebaseHelper and RefsHelper take BaseBranchHelper at
construction since helpers don't have access to Helpers() the way
controllers do.
This commit is contained in:
Stefan Haller 2026-05-21 21:13:00 +02:00
parent 672a37031d
commit 98a421091f
4 changed files with 17 additions and 21 deletions

View file

@ -25,8 +25,9 @@ func (gui *Gui) resetHelpersAndControllers() {
helperCommon := gui.c
recordDirectoryHelper := helpers.NewRecordDirectoryHelper(helperCommon)
reposHelper := helpers.NewRecentReposHelper(helperCommon, recordDirectoryHelper, gui.onSwitchToNewRepo)
rebaseHelper := helpers.NewMergeAndRebaseHelper(helperCommon)
refsHelper := helpers.NewRefsHelper(helperCommon, rebaseHelper)
baseBranchHelper := helpers.NewBaseBranchHelper(helperCommon)
rebaseHelper := helpers.NewMergeAndRebaseHelper(helperCommon, baseBranchHelper)
refsHelper := helpers.NewRefsHelper(helperCommon, rebaseHelper, baseBranchHelper)
suggestionsHelper := helpers.NewSuggestionsHelper(helperCommon)
worktreeHelper := helpers.NewWorktreeHelper(helperCommon, reposHelper, refsHelper, suggestionsHelper)

View file

@ -291,14 +291,10 @@ func (self *BranchesController) viewUpstreamOptions(selectedBranch *models.Branc
}
var disabledReason *types.DisabledReason
candidates, err := self.c.Git().Loaders.BranchLoader.GetBaseBranchCandidates(selectedBranch, self.c.Model().MainBranches)
baseBranch, _, _, err := self.c.Helpers().BaseBranch.ResolveBaseBranch(selectedBranch)
if err != nil {
return err
}
baseBranch := ""
if len(candidates) > 0 {
baseBranch = candidates[0]
}
if baseBranch == "" {
baseBranch = self.c.Tr.CouldNotDetermineBaseBranch
disabledReason = &types.DisabledReason{Text: self.c.Tr.CouldNotDetermineBaseBranch}

View file

@ -19,6 +19,8 @@ import (
type MergeAndRebaseHelper struct {
c *HelperCommon
baseBranchHelper *BaseBranchHelper
// Whether the "continue the rebase/merge?" prompt is currently on screen.
// We use this to auto-dismiss it if the operation stops being in the state
// that the prompt is offering to act on (e.g. it was continued or aborted
@ -29,9 +31,11 @@ type MergeAndRebaseHelper struct {
func NewMergeAndRebaseHelper(
c *HelperCommon,
baseBranchHelper *BaseBranchHelper,
) *MergeAndRebaseHelper {
return &MergeAndRebaseHelper{
c: c,
c: c,
baseBranchHelper: baseBranchHelper,
}
}
@ -343,14 +347,10 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error {
disabledReason = &types.DisabledReason{Text: self.c.Tr.CantRebaseOntoSelf}
}
candidates, err := self.c.Git().Loaders.BranchLoader.GetBaseBranchCandidates(checkedOutBranch, self.c.Model().MainBranches)
baseBranch, _, _, err := self.baseBranchHelper.ResolveBaseBranch(checkedOutBranch)
if err != nil {
return err
}
baseBranch := ""
if len(candidates) > 0 {
baseBranch = candidates[0]
}
if baseBranch == "" {
baseBranch = self.c.Tr.CouldNotDetermineBaseBranch
baseBranchDisabledReason = &types.DisabledReason{Text: self.c.Tr.CouldNotDetermineBaseBranch}

View file

@ -18,16 +18,19 @@ import (
type RefsHelper struct {
c *HelperCommon
rebaseHelper *MergeAndRebaseHelper
rebaseHelper *MergeAndRebaseHelper
baseBranchHelper *BaseBranchHelper
}
func NewRefsHelper(
c *HelperCommon,
rebaseHelper *MergeAndRebaseHelper,
baseBranchHelper *BaseBranchHelper,
) *RefsHelper {
return &RefsHelper{
c: c,
rebaseHelper: rebaseHelper,
c: c,
rebaseHelper: rebaseHelper,
baseBranchHelper: baseBranchHelper,
}
}
@ -428,14 +431,10 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest
func (self *RefsHelper) MoveCommitsToNewBranch() error {
currentBranch := self.c.Model().Branches[0]
candidates, err := self.c.Git().Loaders.BranchLoader.GetBaseBranchCandidates(currentBranch, self.c.Model().MainBranches)
baseBranchRef, _, _, err := self.baseBranchHelper.ResolveBaseBranch(currentBranch)
if err != nil {
return err
}
baseBranchRef := ""
if len(candidates) > 0 {
baseBranchRef = candidates[0]
}
withNewBranchNamePrompt := func(baseBranchName string, f func(string) error) error {
prompt := utils.ResolvePlaceholderString(