fix(cmd): resolve main repo root for pool commands run inside a worktree#51
Open
thirdreplicator wants to merge 1 commit into
Open
Conversation
get, status, prune, init, and return's cwd fallback used the current
worktree's own toplevel as the repo root. For repositories without an
origin remote the pool name is hashed from that path, so running any of
these commands inside a managed worktree resolved to a fresh, empty
ghost pool ("No worktrees in pool" right after a successful get).
Route them through the new git.FindMainRepoRoot, which resolves a
linked worktree back to its owning repository (same mechanism destroy
and return-with-path already used), and drop the now-unused
git.FindRepoRoot.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Running
get,status,prune,init, orreturn(without a path) from inside a managed worktree resolves the wrong pool when the repository has nooriginremote.These commands used
git rev-parse --show-toplevel, which inside a linked worktree returns the worktree's own path.ResolvePoolDirhashes the remote URL when one exists — masking the bug — but for remote-less repos it falls back to hashing the repo path, so the worktree path hashes to a brand-new pool name. The result right after a successfulget:Each such invocation also litters
~/.treehousewith empty ghost pool directories, andgetfrom inside a worktree creates real worktrees in a ghost pool thatstatus/prunefrom the main repo never see.destroyandreturn <path>already handled this correctly viaFindMainRepoRootFrom(git-common-dir resolution).Fix
git.FindMainRepoRoot(), the cwd variant ofFindMainRepoRootFrom, which resolves a linked worktree back to its owning repository.get,status,prune,init, andreturn's cwd fallback through it.git.FindRepoRoot.Testing
TestCommandsInsideWorktreeUseMainRepoPooluses a remote-less repo (the existing fixtures all have anorigin, which hides the bug). It fails onmainwith the exact reported symptom ("No worktrees in pool") and passes with this change. It also verifiesgetfrom inside a worktree acquires from the same pool and that no ghost pool directory appears.go test ./...green,go vetclean,GOOS=windows go build ./...OK.🤖 Generated with Claude Code