summaryrefslogtreecommitdiffstats
path: root/pkg/gui
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-07-24 17:16:59 +1000
committerJesse Duffield <jessedduffield@gmail.com>2023-07-30 18:35:23 +1000
commitb3060065d9a776c755903a1297ab3954c01853a8 (patch)
tree84891e7b8be47a734b8e709fce779c4257e14d48 /pkg/gui
parenta313b1670496e1e73745b5a6a922432fb81ce0e6 (diff)
Support fastforwarding worktree
Diffstat (limited to 'pkg/gui')
-rw-r--r--pkg/gui/controllers/branches_controller.go30
1 files changed, 28 insertions, 2 deletions
diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go
index 623514638..4415fb012 100644
--- a/pkg/gui/controllers/branches_controller.go
+++ b/pkg/gui/controllers/branches_controller.go
@@ -3,6 +3,7 @@ package controllers
import (
"errors"
"fmt"
+ "os"
"strings"
"github.com/jesseduffield/gocui"
@@ -426,15 +427,23 @@ func (self *BranchesController) fastForward(branch *models.Branch) error {
)
return self.c.WithLoaderPanel(message, func(task gocui.Task) error {
- if branch == self.c.Helpers().Refs.GetCheckedOutRef() {
+ worktree, ok := self.worktreeForBranch(branch)
+ if ok {
self.c.LogAction(action)
+ worktreeGitDir := ""
+ // if it is the current worktree path, no need to specify the path
+ if !git_commands.IsCurrentWorktree(worktree.Path) {
+ worktreeGitDir = worktree.GitDir
+ }
+
err := self.c.Git().Sync.Pull(
task,
git_commands.PullOptions{
RemoteName: branch.UpstreamRemote,
BranchName: branch.UpstreamBranch,
FastForwardOnly: true,
+ WorktreeGitDir: worktreeGitDir,
},
)
if err != nil {
@@ -444,7 +453,10 @@ func (self *BranchesController) fastForward(branch *models.Branch) error {
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
} else {
self.c.LogAction(action)
- err := self.c.Git().Sync.FastForward(task, branch.Name, branch.UpstreamRemote, branch.UpstreamBranch)
+
+ err := self.c.Git().Sync.FastForward(
+ task, branch.Name, branch.UpstreamRemote, branch.UpstreamBranch,
+ )
if err != nil {
_ = self.c.Error(err)
}
@@ -455,6 +467,20 @@ func (self *BranchesController) fastForward(branch *models.Branch) error {
})
}
+func (self *BranchesController) worktreePathForBranch(branch *models.Branch) string {
+ worktreeForRef, ok := self.worktreeForBranch(branch)
+ if ok {
+ return worktreeForRef.Path
+ }
+
+ dir, err := os.Getwd()
+ if err != nil {
+ // swallow for now
+ return ""
+ }
+ return dir
+}
+
func (self *BranchesController) createTag(branch *models.Branch) error {
return self.c.Helpers().Tags.OpenCreateTagPrompt(branch.FullRefName(), func() {})
}