From d3f16e5d3be7a0d240688b3a02ce859795dd9158 Mon Sep 17 00:00:00 2001 From: Paul Nodet <5941125+pnodet@users.noreply.github.com> Date: Thu, 11 Jun 2026 03:34:39 +0200 Subject: [PATCH] Add test showing cherry-pick copy/paste doesn't survive a worktree switch The cherry-pick clipboard lives in GuiRepoState.Modes, and we keep a separate GuiRepoState per worktree (RepoStateMap is keyed by the worktree path). Switching worktrees swaps in that worktree's own state, whose clipboard is empty, so pasting is disabled. The copied commits aren't cleared; they're stranded on the previous worktree's state and reappear when switching back. --- pkg/integration/tests/test_list.go | 1 + .../worktree/cherry_pick_across_worktrees.go | 63 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 pkg/integration/tests/worktree/cherry_pick_across_worktrees.go diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 1b264e50d..1ddbee5af 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -490,6 +490,7 @@ var tests = []*components.IntegrationTest{ worktree.AssociateBranchRebase, worktree.BareRepo, worktree.BareRepoWorktreeConfig, + worktree.CherryPickAcrossWorktrees, worktree.Crud, worktree.CustomCommand, worktree.DetachWorktreeFromBranch, diff --git a/pkg/integration/tests/worktree/cherry_pick_across_worktrees.go b/pkg/integration/tests/worktree/cherry_pick_across_worktrees.go new file mode 100644 index 000000000..ef5bb0d2a --- /dev/null +++ b/pkg/integration/tests/worktree/cherry_pick_across_worktrees.go @@ -0,0 +1,63 @@ +package worktree + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var CherryPickAcrossWorktrees = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Copy a commit in one worktree and paste it in another worktree of the same repo", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.NewBranch("mybranch") + shell.EmptyCommit("base") + // the linked worktree's branch stays at "base" + shell.AddWorktree("mybranch", "../linked-worktree", "newbranch") + shell.EmptyCommit("one") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + Focus(). + Lines( + Contains("one").IsSelected(), + Contains("base"), + ). + Press(keys.Commits.CherryPickCopy) + + t.Views().Information().Content(Contains("1 commit copied")) + + t.Views().Worktrees(). + Focus(). + Lines( + Contains("(main worktree)").IsSelected(), + Contains("linked-worktree"), + ). + NavigateToLine(Contains("linked-worktree")). + Press(keys.Universal.Select) + + t.Views().Commits(). + Focus(). + Lines( + Contains("base"), + ). + Press(keys.Commits.PasteCommits) + + /* EXPECTED: + t.ExpectPopup().Alert(). + Title(Equals("Cherry-pick")). + Content(Contains("Are you sure you want to cherry-pick the 1 copied commit(s) onto this branch?")). + Confirm() + + t.Views().Information().Content(DoesNotContain("commit copied")) + + t.Views().Commits(). + Lines( + Contains("one"), + Contains("base").IsSelected(), + ) + ACTUAL: */ + t.ExpectToast(Equals("Disabled: No copied commits")) + }, +})