Skip to content

Allow pasting cherry-picked commits in a different worktree of the same repo#5688

Open
pnodet wants to merge 2 commits into
jesseduffield:masterfrom
pnodet:cherry-pick-across-worktrees
Open

Allow pasting cherry-picked commits in a different worktree of the same repo#5688
pnodet wants to merge 2 commits into
jesseduffield:masterfrom
pnodet:cherry-pick-across-worktrees

Conversation

@pnodet

@pnodet pnodet commented Jun 11, 2026

Copy link
Copy Markdown

Copying commits with c/C and then switching to another worktree of the same
repo would disable pasting with V ("No copied commits"). The copied commits
weren't actually cleared — the clipboard lives in GuiRepoState.Modes, and we
keep a separate GuiRepoState per worktree, so the selection was stranded on
the previous worktree's state (it even reappeared when switching back).

There's no git-level reason for this limitation: pasting runs
git cherry-pick <hashes>, and hashes resolve identically in every worktree of
a repo since they share one object database.

This PR moves the clipboard out of the per-worktree GuiRepoState into a new
SharedRepoState, of which there is one instance per repo, keyed by the repo's
common git dir. Every worktree's Modes.CherryPicking now points at the same
instance. The common git dir is shared by all worktrees of a repo (including
worktrees of bare repos) but distinct for submodules and unrelated repos, so
those keep isolated clipboards.

Side effects of sharing the whole struct, both intended:

  • Cancelling cherry-picking (Esc) in one worktree now clears it in all of
    them.
  • Pasting in one worktree hides the copied-commits indicator (and the blue
    highlight) in the others too, while still allowing a repeat paste, matching
    the existing single-worktree behavior after a paste.

The first commit adds an integration test demonstrating the old behavior; the
second contains the fix and flips the test to the new expectation.

pnodet added 2 commits June 11, 2026 07:58
…itch

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.
Copied commits are referenced by hash, and hashes resolve identically in
every worktree of a repo (shared object database), so there's no reason
pasting shouldn't work after switching worktrees. Move the clipboard out
of the per-worktree GuiRepoState into a per-repo SharedRepoState, keyed
by the repo's common git dir; every worktree's Modes.CherryPicking now
points at the same instance. Submodules and unrelated repos have
different git dirs, so they keep isolated clipboards. As a side effect,
cancelling a cherry-pick in one worktree now correctly clears it in all
of them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant