mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-10-06 22:16:22 -04:00
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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
c3b09cebad
commit
bfb8c91b7b
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user