Skip to content

Share the command history across a repository's checkouts - #2152

Merged
bbatsov merged 1 commit into
masterfrom
feature/1786-shared-command-history
Aug 10, 2026
Merged

Share the command history across a repository's checkouts#2152
bbatsov merged 1 commit into
masterfrom
feature/1786-shared-command-history

Conversation

@bbatsov

@bbatsov bbatsov commented Aug 10, 2026

Copy link
Copy Markdown
Owner

Fixes #1786.

Working on two branches means two directories, and you build and test the project the same way in both. Until now each checkout learned the commands separately, so a worktree made this morning greeted you with an empty history and you retyped everything.

The per-command-type histories - the ones behind M-p at a prompt - are now keyed by the repository rather than the directory, so a fresh worktree or a second clone offers the commands the project is actually built with. This is what the identity layer from #2147 was for.

Two things deliberately stay local to the checkout you're in: what a prompt is pre-filled with, and what projectile-repeat-last-command replays. My first draft shared the combined history too, and a review caught what that meant in practice - in a worktree the repeat binding rebuilt the other tree, unprompted, while you thought you were building the one you were sitting in. The browsable history is safe to share precisely because reaching for it is a deliberate act.

Same review caught that these histories are persisted through savehist, so keying them differently would have silently emptied every existing project's history on upgrade day - the exact opposite of the point. A history found under the old per-root key is adopted as the repository's.

projectile-command-history-scope set to project restores the old per-directory behaviour, and it's safe as a file-local so you can set it for the odd repo whose clones are genuinely built differently.

Working on two branches means two directories, and the commands you build
and test the project with are the same in both. Until now each checkout
learned them separately, so a worktree made this morning greeted you with
an empty history and you retyped everything.

The per-command-type histories - the ones behind M-p at a prompt - are now
keyed by the repository rather than by the directory, so a fresh worktree
or a second clone offers the commands the project is actually built with.
That's what `projectile-repo-identity' was for.

Two things deliberately stay local to the checkout you're in, because both
act without asking and a remembered command can carry absolute paths back
into the checkout it was typed in: what a prompt is pre-filled with, and
what `projectile-repeat-last-command' replays. The first draft shared the
combined history too, and in a worktree the repeat binding then rebuilt
the *other* tree unprompted - the browsable history is safe to share
precisely because reaching for it is a deliberate act.

The histories are persisted, so an upgrade would have walked into a
project you have been building for years with nothing in hand. A history
found under the old per-root key is adopted as the repository's.
@bbatsov
bbatsov merged commit 8ac2b42 into master Aug 10, 2026
10 checks passed
@bbatsov
bbatsov deleted the feature/1786-shared-command-history branch August 10, 2026 06:04
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.

Shared/pre-defined command history for work-trees of same project

1 participant