From bfb8c91b7b91aa708bfa7d3e4aa71792a74e6ff5 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sun, 20 Sep 2026 17:05:35 +0200 Subject: [PATCH] Split pushing the current branch into resolving its destination and pushing Pushing the current branch has three cases: it has an upstream, it has none but push.default is "current", or the user is prompted for one. Each case ends in a push, and the first one also checks whether a force push is needed. Let the three cases call a common callback instead, and put the check and the push there. This makes it possible to run the same three cases with a different callback, so that the branches stacked below the current one can be pushed along with it. The check returns false for a branch without an upstream, so the other two cases behave as before. Co-Authored-By: Claude Fable 5.1 --- pkg/gui/controllers/sync_controller.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/pkg/gui/controllers/sync_controller.go b/pkg/gui/controllers/sync_controller.go index d787a54a8..08ffc3051 100644 --- a/pkg/gui/controllers/sync_controller.go +++ b/pkg/gui/controllers/sync_controller.go @@ -87,18 +87,26 @@ func (self *SyncController) branchCheckedOut(f func(*models.Branch) error) func( } func (self *SyncController) push(currentBranch *models.Branch) error { - // if we are behind our upstream branch we'll ask if the user wants to force push - if currentBranch.IsTrackingRemote() { - opts := pushOpts{remoteBranchStoredLocally: currentBranch.RemoteBranchStoredLocally()} + return self.resolvePushOfCurrentBranch(currentBranch, func(opts pushOpts) error { + // if we are behind our upstream branch we'll ask if the user wants to force push if currentBranch.IsBehindForPush() { return self.requestToForcePush(currentBranch, opts) } return self.pushAux(currentBranch, opts) + }) +} + +// Works out where the current branch is pushed to: to its upstream, to a +// branch of the same name if push.default is "current", or to an upstream the +// user enters in a prompt. Calls onResolved with the options for that push. +func (self *SyncController) resolvePushOfCurrentBranch(currentBranch *models.Branch, onResolved func(pushOpts) error) error { + if currentBranch.IsTrackingRemote() { + return onResolved(pushOpts{remoteBranchStoredLocally: currentBranch.RemoteBranchStoredLocally()}) } if self.c.Git().Config.GetPushToCurrent() { - return self.pushAux(currentBranch, pushOpts{setUpstream: true}) + return onResolved(pushOpts{setUpstream: true}) } return self.c.Helpers().Upstream.PromptForUpstreamWithInitialContent(currentBranch, func(upstream string) error { @@ -107,7 +115,7 @@ func (self *SyncController) push(currentBranch *models.Branch) error { return err } - return self.pushAux(currentBranch, pushOpts{ + return onResolved(pushOpts{ setUpstream: true, upstreamRemote: upstreamRemote, upstreamBranch: upstreamBranch,