mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
Support fastforwarding worktree
This commit is contained in:
@ -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() {})
|
||||
}
|
||||
|
Reference in New Issue
Block a user