From dcf0532020262ab72932a06fb86f901a6239c83e Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 21 May 2026 21:21:30 +0200 Subject: [PATCH] Prompt for base branch when viewing divergence is ambiguous Pressing 'b' on the branches view's divergence menu now shows the disambiguation menu when the selected branch's fork point is reachable from more than one configured main branch. The user's selection drives the sub-commits view and gets recorded so subsequent actions on the branch skip the prompt. --- pkg/gui/controllers/branches_controller.go | 30 +++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index 6d5bcdb7d..c4f94b4cd 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -291,15 +291,16 @@ func (self *BranchesController) viewUpstreamOptions(selectedBranch *models.Branc } var disabledReason *types.DisabledReason - baseBranch, _, _, err := self.c.Helpers().BaseBranch.ResolveBaseBranch(selectedBranch) + baseBranch, baseAmbiguous, baseCandidates, err := self.c.Helpers().BaseBranch.ResolveBaseBranch(selectedBranch) if err != nil { return err } - if baseBranch == "" { - baseBranch = self.c.Tr.CouldNotDetermineBaseBranch + baseBranchLabel := baseBranch + if baseBranchLabel == "" { + baseBranchLabel = self.c.Tr.CouldNotDetermineBaseBranch disabledReason = &types.DisabledReason{Text: self.c.Tr.CouldNotDetermineBaseBranch} } - shortBaseBranchName := helpers.ShortBranchName(baseBranch) + shortBaseBranchName := helpers.ShortBranchName(baseBranchLabel) label := utils.ResolvePlaceholderString( self.c.Tr.ViewDivergenceFromBaseBranch, map[string]string{"baseBranch": shortBaseBranchName}, @@ -312,14 +313,19 @@ func (self *BranchesController) viewUpstreamOptions(selectedBranch *models.Branc if branch == nil { return nil } - - return self.c.Helpers().SubCommits.ViewSubCommits(helpers.ViewSubCommitsOpts{ - Ref: branch, - TitleRef: fmt.Sprintf("%s <-> %s", branch.RefName(), shortBaseBranchName), - RefToShowDivergenceFrom: baseBranch, - Context: self.context(), - ShowBranchHeads: false, - }) + showDivergence := func(base string) error { + return self.c.Helpers().SubCommits.ViewSubCommits(helpers.ViewSubCommitsOpts{ + Ref: branch, + TitleRef: fmt.Sprintf("%s <-> %s", branch.RefName(), helpers.ShortBranchName(base)), + RefToShowDivergenceFrom: base, + Context: self.context(), + ShowBranchHeads: false, + }) + } + if baseAmbiguous { + return self.c.Helpers().BaseBranch.ShowPicker(branch, baseCandidates, showDivergence) + } + return showDivergence(baseBranch) }, DisabledReason: disabledReason, }