Skip to content

Commit a43e67d

Browse files
committed
Add worktree option to fast forwarding operation
1 parent 095eb13 commit a43e67d

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

pkg/commands/git_commands/git_command_builder.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ func (self *GitCommandBuilder) Worktree(path string) *GitCommandBuilder {
7676
return self
7777
}
7878

79+
func (self *GitCommandBuilder) WorktreePathIf(condition bool, path string) *GitCommandBuilder {
80+
if condition {
81+
return self.Worktree(path)
82+
}
83+
84+
return self
85+
}
86+
7987
// Note, you may prefer to use the Dir method instead of this one
8088
func (self *GitCommandBuilder) GitDir(path string) *GitCommandBuilder {
8189
// git dir arg comes before the command

pkg/commands/git_commands/sync.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ type PullOptions struct {
8888
BranchName string
8989
FastForwardOnly bool
9090
WorktreeGitDir string
91+
WorktreePath string
9192
}
9293

9394
func (self *SyncCommands) Pull(task gocui.Task, opts PullOptions) error {
@@ -97,9 +98,10 @@ func (self *SyncCommands) Pull(task gocui.Task, opts PullOptions) error {
9798
ArgIf(opts.RemoteName != "", opts.RemoteName).
9899
ArgIf(opts.BranchName != "", "refs/heads/"+opts.BranchName).
99100
GitDirIf(opts.WorktreeGitDir != "", opts.WorktreeGitDir).
101+
WorktreePathIf(opts.WorktreePath != "", opts.WorktreePath).
100102
ToArgv()
101103

102-
// setting GIT_SEQUENCE_EDITOR to ':' as a way of skipping it, in case the user
104+
// setting GIT_SEQUENCE_EDITOR to ':' as a way of skipping if, in case the user
103105
// has 'pull.rebase = interactive' configured.
104106
return self.cmd.New(cmdArgs).AddEnvVars("GIT_SEQUENCE_EDITOR=:").PromptOnCredentialRequest(task).Run()
105107
}

pkg/gui/controllers/branches_controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,9 +611,11 @@ func (self *BranchesController) fastForward(branch *models.Branch) error {
611611
self.c.LogAction(action)
612612

613613
worktreeGitDir := ""
614+
worktreePath := ""
614615
// if it is the current worktree path, no need to specify the path
615616
if !worktree.IsCurrent {
616617
worktreeGitDir = worktree.GitDir
618+
worktreePath = worktree.Path
617619
}
618620

619621
err := self.c.Git().Sync.Pull(
@@ -623,6 +625,7 @@ func (self *BranchesController) fastForward(branch *models.Branch) error {
623625
BranchName: branch.UpstreamBranch,
624626
FastForwardOnly: true,
625627
WorktreeGitDir: worktreeGitDir,
628+
WorktreePath: worktreePath,
626629
},
627630
)
628631
_ = self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})

0 commit comments

Comments
 (0)