Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pkg/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ type Gui struct {

CustomCommandsClient *custom_commands.Client

// Unlike the other modes, the cherry-picking mode is shared by all repo
// states, so that you can copy commits in one worktree or repo and paste
// them in another.
cherryPicking *cherrypicking.CherryPicking

// this is a mapping of repos to gui states, so that we can restore the original
// gui state when returning from a subrepo.
// In repos with multiple worktrees, we store a separate repo state per worktree.
Expand Down Expand Up @@ -647,7 +652,7 @@ func (gui *Gui) resetState(startArgs appTypes.StartArgs) types.Context {
},
Modes: &types.Modes{
Filtering: filtering.New(startArgs.FilterPath, ""),
CherryPicking: cherrypicking.New(),
CherryPicking: gui.cherryPicking,
Diffing: diffing.New(),
MarkedBaseCommit: marked_base_commit.New(),
},
Expand Down Expand Up @@ -800,6 +805,7 @@ func NewGui(
showRecentRepos: showRecentRepos,
RepoPathStack: &utils.Stack[types.RepoLocation]{},
RepoStateMap: map[Repo]*GuiRepoState{},
cherryPicking: cherrypicking.New(),
GuiLog: []string{},

// initializing this to true for the time being; it will be reset to the
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/types/modes.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

type Modes struct {
Filtering filtering.Filtering
CherryPicking *cherrypicking.CherryPicking
CherryPicking *cherrypicking.CherryPicking // shared by all repo states; see Gui.cherryPicking
Diffing diffing.Diffing
MarkedBaseCommit marked_base_commit.MarkedBaseCommit
}
79 changes: 79 additions & 0 deletions pkg/integration/tests/cherry_pick/cherry_pick_across_worktrees.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package cherry_pick

import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)

var CherryPickAcrossWorktrees = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Copy commits in one worktree, drop them there, and paste them in another worktree",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.
EmptyCommit("base").
AddWorktree("master", "../linked-worktree", "newbranch").
EmptyCommit("one").
EmptyCommit("two")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Lines(
Contains("two").IsSelected(),
Contains("one"),
Contains("base"),
).
Press(keys.Universal.RangeSelectDown).
Press(keys.Commits.CherryPickCopy).
Tap(func() {
t.Views().Information().Content(Contains("2 commits copied"))
}).
Press(keys.Universal.Remove).
Tap(func() {
t.ExpectPopup().Confirmation().
Title(Equals("Drop commit")).
Content(Contains("Are you sure you want to drop the selected commit(s)?")).
Confirm()
}).
Lines(
Contains("base").IsSelected(),
)

t.Views().Branches().
Focus().
NavigateToLine(Contains("newbranch")).
Press(keys.Universal.Select).
Tap(func() {
t.ExpectPopup().Confirmation().
Title(Equals("Switch to worktree")).
Content(Equals("This branch is checked out by worktree linked-worktree. Do you want to switch to that worktree?")).
Confirm()
}).
Lines(
Contains("newbranch").IsSelected(),
Contains("master (worktree repo)"),
)

t.Views().Information().Content(Contains("2 commits copied"))

t.Views().Commits().
Focus().
Lines(
Contains("base").IsSelected(),
).
Press(keys.Commits.PasteCommits).
Tap(func() {
t.ExpectPopup().Alert().
Title(Equals("Cherry-pick")).
Content(Contains("Are you sure you want to cherry-pick the 2 copied commit(s) onto this branch?")).
Confirm()
}).
Lines(
Contains("two"),
Contains("one"),
Contains("base").IsSelected(),
)
},
})
1 change: 1 addition & 0 deletions pkg/integration/tests/test_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ var tests = []*components.IntegrationTest{
branch.Suggestions,
branch.UnsetUpstream,
cherry_pick.CherryPick,
cherry_pick.CherryPickAcrossWorktrees,
cherry_pick.CherryPickCommitThatBecomesEmpty,
cherry_pick.CherryPickConflicts,
cherry_pick.CherryPickConflictsEmptyCommitAfterResolving,
Expand Down
Loading