From 0d8b18cfb77be6e372c675c253b14815d17b403d Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Wed, 23 Sep 2026 14:24:53 +0200 Subject: [PATCH] Move fast-forwarding a branch into BranchesHelper Most of the logic of this controller belongs in a helper, and the next commit reshapes it, so move it over unchanged first to keep that diff about the change itself. Co-Authored-By: Claude Opus 5 (1M context) --- pkg/gui/controllers/branches_controller.go | 39 +----------------- .../controllers/helpers/branches_helper.go | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+), 38 deletions(-) diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index f01cf2c0b..cf613430e 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -7,7 +7,6 @@ import ( "github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/models" - "github.com/jesseduffield/lazygit/pkg/gocui" "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers" "github.com/jesseduffield/lazygit/pkg/gui/presentation" @@ -666,43 +665,7 @@ func (self *BranchesController) fastForward(branch *models.Branch) error { return errors.New(self.c.Tr.FwdCommitsToPush) } - action := self.c.Tr.Actions.FastForwardBranch - worktree, ok := self.worktreeForBranch(branch) - - return self.c.WithInlineStatus(branch, types.ItemOperationFastForwarding, context.LOCAL_BRANCHES_CONTEXT_KEY, func(task gocui.Task) error { - if ok { - self.c.LogAction(action) - - worktreeGitDir := "" - worktreePath := "" - // if it is the current worktree path, no need to specify the path - if !worktree.IsCurrent { - worktreeGitDir = worktree.GitDir - worktreePath = worktree.Path - } - - err := self.c.Git().Sync.Pull( - task, - git_commands.PullOptions{ - RemoteName: branch.UpstreamRemote, - BranchName: branch.UpstreamBranch, - FastForwardOnly: true, - WorktreeGitDir: worktreeGitDir, - WorktreePath: worktreePath, - }, - ) - self.c.RefreshFromWorker(types.RefreshOptions{}) - return err - } - - self.c.LogAction(action) - - err := self.c.Git().Sync.FastForward( - task, branch.Name, branch.UpstreamRemote, branch.UpstreamBranch, - ) - self.c.RefreshFromWorker(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES}}) - return err - }) + return self.c.Helpers().BranchesHelper.FastForwardBranch(branch) } func (self *BranchesController) createTag(branch *models.Branch) error { diff --git a/pkg/gui/controllers/helpers/branches_helper.go b/pkg/gui/controllers/helpers/branches_helper.go index e87edb460..75cb788ca 100644 --- a/pkg/gui/controllers/helpers/branches_helper.go +++ b/pkg/gui/controllers/helpers/branches_helper.go @@ -8,6 +8,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gocui" + "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" "github.com/samber/lo" @@ -433,6 +434,46 @@ func (self *BranchesHelper) PostFetchRefresh(fetchErr error, background bool, fe return fetchErr } +func (self *BranchesHelper) FastForwardBranch(branch *models.Branch) error { + action := self.c.Tr.Actions.FastForwardBranch + worktree, ok := self.worktreeForBranch(branch) + + return self.c.WithInlineStatus(branch, types.ItemOperationFastForwarding, context.LOCAL_BRANCHES_CONTEXT_KEY, func(task gocui.Task) error { + if ok { + self.c.LogAction(action) + + worktreeGitDir := "" + worktreePath := "" + // if it is the current worktree path, no need to specify the path + if !worktree.IsCurrent { + worktreeGitDir = worktree.GitDir + worktreePath = worktree.Path + } + + err := self.c.Git().Sync.Pull( + task, + git_commands.PullOptions{ + RemoteName: branch.UpstreamRemote, + BranchName: branch.UpstreamBranch, + FastForwardOnly: true, + WorktreeGitDir: worktreeGitDir, + WorktreePath: worktreePath, + }, + ) + self.c.RefreshFromWorker(types.RefreshOptions{}) + return err + } + + self.c.LogAction(action) + + err := self.c.Git().Sync.FastForward( + task, branch.Name, branch.UpstreamRemote, branch.UpstreamBranch, + ) + self.c.RefreshFromWorker(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES}}) + return err + }) +} + func (self *BranchesHelper) AutoForwardBranches(background bool) error { if self.c.UserConfig().Git.AutoForwardBranches == "none" { return nil