mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-08-07 22:02:56 +03:00
Add worktree option to fast forwarding operation
This commit is contained in:
committed by
Jesse Duffield
parent
c4e59aea66
commit
e1c18226bf
@@ -76,6 +76,14 @@ func (self *GitCommandBuilder) Worktree(path string) *GitCommandBuilder {
|
|||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *GitCommandBuilder) WorktreePathIf(condition bool, path string) *GitCommandBuilder {
|
||||||
|
if condition {
|
||||||
|
return self.Worktree(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
return self
|
||||||
|
}
|
||||||
|
|
||||||
// Note, you may prefer to use the Dir method instead of this one
|
// Note, you may prefer to use the Dir method instead of this one
|
||||||
func (self *GitCommandBuilder) GitDir(path string) *GitCommandBuilder {
|
func (self *GitCommandBuilder) GitDir(path string) *GitCommandBuilder {
|
||||||
// git dir arg comes before the command
|
// git dir arg comes before the command
|
||||||
|
@@ -88,6 +88,7 @@ type PullOptions struct {
|
|||||||
BranchName string
|
BranchName string
|
||||||
FastForwardOnly bool
|
FastForwardOnly bool
|
||||||
WorktreeGitDir string
|
WorktreeGitDir string
|
||||||
|
WorktreePath string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *SyncCommands) Pull(task gocui.Task, opts PullOptions) error {
|
func (self *SyncCommands) Pull(task gocui.Task, opts PullOptions) error {
|
||||||
@@ -97,6 +98,7 @@ func (self *SyncCommands) Pull(task gocui.Task, opts PullOptions) error {
|
|||||||
ArgIf(opts.RemoteName != "", opts.RemoteName).
|
ArgIf(opts.RemoteName != "", opts.RemoteName).
|
||||||
ArgIf(opts.BranchName != "", "refs/heads/"+opts.BranchName).
|
ArgIf(opts.BranchName != "", "refs/heads/"+opts.BranchName).
|
||||||
GitDirIf(opts.WorktreeGitDir != "", opts.WorktreeGitDir).
|
GitDirIf(opts.WorktreeGitDir != "", opts.WorktreeGitDir).
|
||||||
|
WorktreePathIf(opts.WorktreePath != "", opts.WorktreePath).
|
||||||
ToArgv()
|
ToArgv()
|
||||||
|
|
||||||
// setting GIT_SEQUENCE_EDITOR to ':' as a way of skipping it, in case the user
|
// setting GIT_SEQUENCE_EDITOR to ':' as a way of skipping it, in case the user
|
||||||
|
@@ -629,9 +629,11 @@ func (self *BranchesController) fastForward(branch *models.Branch) error {
|
|||||||
self.c.LogAction(action)
|
self.c.LogAction(action)
|
||||||
|
|
||||||
worktreeGitDir := ""
|
worktreeGitDir := ""
|
||||||
|
worktreePath := ""
|
||||||
// if it is the current worktree path, no need to specify the path
|
// if it is the current worktree path, no need to specify the path
|
||||||
if !worktree.IsCurrent {
|
if !worktree.IsCurrent {
|
||||||
worktreeGitDir = worktree.GitDir
|
worktreeGitDir = worktree.GitDir
|
||||||
|
worktreePath = worktree.Path
|
||||||
}
|
}
|
||||||
|
|
||||||
err := self.c.Git().Sync.Pull(
|
err := self.c.Git().Sync.Pull(
|
||||||
@@ -641,6 +643,7 @@ func (self *BranchesController) fastForward(branch *models.Branch) error {
|
|||||||
BranchName: branch.UpstreamBranch,
|
BranchName: branch.UpstreamBranch,
|
||||||
FastForwardOnly: true,
|
FastForwardOnly: true,
|
||||||
WorktreeGitDir: worktreeGitDir,
|
WorktreeGitDir: worktreeGitDir,
|
||||||
|
WorktreePath: worktreePath,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
_ = self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
|
_ = self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
|
||||||
|
@@ -380,6 +380,7 @@ var tests = []*components.IntegrationTest{
|
|||||||
worktree.DoubleNestedLinkedSubmodule,
|
worktree.DoubleNestedLinkedSubmodule,
|
||||||
worktree.ExcludeFileInWorktree,
|
worktree.ExcludeFileInWorktree,
|
||||||
worktree.FastForwardWorktreeBranch,
|
worktree.FastForwardWorktreeBranch,
|
||||||
|
worktree.FastForwardWorktreeBranchShouldNotPolluteCurrentWorktree,
|
||||||
worktree.ForceRemoveWorktree,
|
worktree.ForceRemoveWorktree,
|
||||||
worktree.RemoveWorktreeFromBranch,
|
worktree.RemoveWorktreeFromBranch,
|
||||||
worktree.ResetWindowTabs,
|
worktree.ResetWindowTabs,
|
||||||
|
@@ -0,0 +1,59 @@
|
|||||||
|
package worktree
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
|
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||||
|
)
|
||||||
|
|
||||||
|
var FastForwardWorktreeBranchShouldNotPolluteCurrentWorktree = NewIntegrationTest(NewIntegrationTestArgs{
|
||||||
|
Description: "Fast-forward a linked worktree branch from another worktree",
|
||||||
|
ExtraCmdArgs: []string{},
|
||||||
|
Skip: false,
|
||||||
|
SetupConfig: func(config *config.AppConfig) {},
|
||||||
|
SetupRepo: func(shell *Shell) {
|
||||||
|
// both main and linked worktree will have changed to fast-forward
|
||||||
|
shell.NewBranch("mybranch")
|
||||||
|
shell.CreateFileAndAdd("README.md", "hello world")
|
||||||
|
shell.Commit("initial commit")
|
||||||
|
shell.EmptyCommit("two")
|
||||||
|
shell.EmptyCommit("three")
|
||||||
|
shell.NewBranch("newbranch")
|
||||||
|
|
||||||
|
shell.CloneIntoRemote("origin")
|
||||||
|
shell.SetBranchUpstream("mybranch", "origin/mybranch")
|
||||||
|
shell.SetBranchUpstream("newbranch", "origin/newbranch")
|
||||||
|
|
||||||
|
// remove the 'three' commit so that we have something to pull from the remote
|
||||||
|
shell.HardReset("HEAD^")
|
||||||
|
shell.Checkout("mybranch")
|
||||||
|
shell.HardReset("HEAD^")
|
||||||
|
|
||||||
|
shell.AddWorktreeCheckout("newbranch", "../linked-worktree")
|
||||||
|
},
|
||||||
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
|
t.Views().Branches().
|
||||||
|
Focus().
|
||||||
|
Lines(
|
||||||
|
Contains("mybranch").Contains("↓1").IsSelected(),
|
||||||
|
Contains("newbranch (worktree)").Contains("↓1"),
|
||||||
|
).
|
||||||
|
Press(keys.Branches.FastForward).
|
||||||
|
Lines(
|
||||||
|
Contains("mybranch").Contains("✓").IsSelected(),
|
||||||
|
Contains("newbranch (worktree)").Contains("↓1"),
|
||||||
|
).
|
||||||
|
NavigateToLine(Contains("newbranch (worktree)")).
|
||||||
|
Press(keys.Branches.FastForward).
|
||||||
|
Lines(
|
||||||
|
Contains("mybranch").Contains("✓"),
|
||||||
|
Contains("newbranch (worktree)").Contains("✓").IsSelected(),
|
||||||
|
).
|
||||||
|
NavigateToLine(Contains("mybranch"))
|
||||||
|
|
||||||
|
// check the current worktree that it has no lines in the File changes pane
|
||||||
|
t.Views().Files().
|
||||||
|
Focus().
|
||||||
|
Press(keys.Files.RefreshFiles).
|
||||||
|
LineCount(EqualsInt(0))
|
||||||
|
},
|
||||||
|
})
|
Reference in New Issue
Block a user