Skip to content

fix(worktrees): group a bare clone's worktrees under the clone (#1049) - #1116

Open
agegr wants to merge 1 commit into
mainfrom
fix/bare-clone-worktrees
Open

agegr wants to merge 1 commit into
mainfrom
fix/bare-clone-worktrees

Conversation

@agegr

@agegr agegr commented Oct 8, 2026

Copy link
Copy Markdown
Owner

A worktree's project root was the parent of its common git dir. For a bare clone (parent/repo.git) that parent is the folder holding every clone, so the worktrees of all repos there fell into one project group (and parent became an allowed file root), while the clone itself resolved to its own, empty project. "New worktree…" also ran git worktree add from parent, which is not a repository.

Reproduced with real git clone --bare + git worktree add: parent/repo1.git/worktree1 and parent/repo2.git/worktree1 both resolved to parent.

  • lib/worktree.ts: repoRootFromCommonDir() — the folder holding the common git dir is the root only when that dir is .git, or a .git file in that folder points at it (the project/.bare layout). Any other bare clone is its own root. Used for project resolution and for getRepoRoot(), so new worktrees are created from the clone (in repo.git-worktrees/).
  • inferRemovedWorktree() recognizes a bare clone (HEAD, objects/, refs/) so sessions of a removed worktree still group back under it.
  • Normal repos and the .bare layout resolve exactly as before.

Test: real-git regression in lib/worktree.test.mjs (two bare clones under one parent, the .bare layout, adding a worktree, a removed worktree); fails on main. Note in docs/agents/files-and-access.md. tsc, eslint, npm test pass.

Closes #1049

🤖 Generated with Claude Code

A worktree's project root was the parent of its common git dir. For a
bare clone (`parent/repo.git`) that parent is the folder holding every
clone, so the worktrees of all repos there fell into one project (and
that folder became an allowed file root), while the clone itself was a
project of its own with none of its sessions. New worktrees were added
from that parent too, which is no repository.

A bare clone is now its own root, unless a `.git` file beside it points
at it (the `project/.bare` layout keeps the enclosing folder). Removed
worktrees under `repo.git-worktrees/` are still inferred back into it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

Bug: The sidebar list is showing session from other git repositories

1 participant