Skip to content

fix(cmd): resolve main repo root for pool commands run inside a worktree - #51

Merged
kunchenguid merged 2 commits into
kunchenguid:mainfrom
thirdreplicator:fix/pool-resolution-inside-worktree
Aug 19, 2026
Merged

kunchenguid merged 2 commits into
kunchenguid:mainfrom
thirdreplicator:fix/pool-resolution-inside-worktree

Conversation

@thirdreplicator

Copy link
Copy Markdown
Contributor

Problem

Running get, status, prune, init, or return (without a path) from inside a managed worktree resolves the wrong pool when the repository has no origin remote.

These commands used git rev-parse --show-toplevel, which inside a linked worktree returns the worktree's own path. ResolvePoolDir hashes 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 successful get:

❯ th get
🌳 Entered worktree at ~/.treehouse/mentor-fe65ca/2/mentor. Type 'exit' to return.
❯ th status
🌳 No worktrees in pool.

Each such invocation also litters ~/.treehouse with empty ghost pool directories, and get from inside a worktree creates real worktrees in a ghost pool that status/prune from the main repo never see.

destroy and return <path> already handled this correctly via FindMainRepoRootFrom (git-common-dir resolution).

Fix

  • Add git.FindMainRepoRoot(), the cwd variant of FindMainRepoRootFrom, which resolves a linked worktree back to its owning repository.
  • Route get, status, prune, init, and return's cwd fallback through it.
  • Remove the now-unused git.FindRepoRoot.

Testing

  • New e2e regression test TestCommandsInsideWorktreeUseMainRepoPool uses a remote-less repo (the existing fixtures all have an origin, which hides the bug). It fails on main with the exact reported symptom ("No worktrees in pool") and passes with this change. It also verifies get from inside a worktree acquires from the same pool and that no ghost pool directory appears.
  • go test ./... green, go vet clean, GOOS=windows go build ./... OK.

🤖 Generated with Claude Code

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 <[email protected]>
@kunchenguid

kunchenguid commented Jul 10, 2026 •

Copy link
Copy Markdown
Owner

Thanks for the PR! This branch currently has a merge conflict with the base branch.

When you get a chance, please rebase onto (or merge) the latest base branch, resolve the conflict, and push. After that, checks will re-run and the PR will get looked at again.

Noted for treehouse#51 at 7fd12a07.

@kunchenguid

Copy link
Copy Markdown
Owner

Automated reminder: this PR still looks blocked on a rebase or merge conflict fix.

If you are still interested, please rebase onto the current base branch, resolve the conflict, and push.

If I do not hear back, I may close this as inactive.

@kunchenguid kunchenguid removed the wheelhouse:pending-contributor-action Managed by Wheelhouse label Aug 11, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is in scope and CI was green on the July head, but GitHub reports a merge conflict with current main. I am not opening a competing implementation. A conflict-only rebase is in flight so the same fix can land. Leaving #51 open.

@kunchenguid

Copy link
Copy Markdown
Owner

No description provided.

@kunchenguid

Copy link
Copy Markdown
Owner

No description provided.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: #97 is closed. We are putting the conflict-only rebase on this branch instead (thirdreplicator:fix/pool-resolution-inside-worktree; maintainer edits are on). Leaving #51 open.

@kunchenguid

Copy link
Copy Markdown
Owner

No description provided.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: we could not write the conflict-only rebase to this branch. The push reached GitHub, then the App token was rejected:

refusing to allow a GitHub App to create or update workflow .github/workflows/ci.yml without workflows permission

Rebasing onto current main includes #95's workflow change, and we cannot push that file to thirdreplicator/treehouse. #97 stays closed. Head is still 7fd12a0. Merge state is still dirty. Stopping here.

@kunchenguid

Copy link
Copy Markdown
Owner

No description provided.

@kunchenguid

Copy link
Copy Markdown
Owner

No description provided.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: conflict-only files are on this branch now (f648be2, parent 7fd12a0). We did not rebase onto main, did not merge main, and did not touch .github/workflows. git merge-tree into current main is clean. #97 stays closed.

CI for this new head is waiting on first-time fork workflow approval. I reviewed the diff (pool-root resolution + e2e test; no workflow or secret changes) and am approving those runs.

@kunchenguid

Copy link
Copy Markdown
Owner

No description provided.

@greptile-apps

greptile-apps Bot commented Aug 19, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (2): Last reviewed commit: "fix(cmd): resolve merge conflicts for po..." | Re-trigger Greptile

Comment thread cmd/get.go
if err != nil {
return fmt.Errorf("not in a git repository: %w", err)
}
repoRoot, err = git.FindMainRepoRoot()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Duplicate repository-root lookup

getRunE calls FindRepoRoot immediately before FindMainRepoRoot repeats the same git rev-parse --show-toplevel lookup, so every get invocation starts an unnecessary Git subprocess and discards its result.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: I cannot approve the first-time fork workflows from here. The shared browser is signed out of GitHub, and I have no Actions approve API. Diff still looks safe (pool-root fix + e2e test; no workflow or secret changes).

Waiting on captain approval for:

Or the PR button: Approve and run workflows on #51

Not tagging @greptileai and not merging until CI is green.

@kunchenguid

Copy link
Copy Markdown
Owner

No description provided.

@greptile-apps

greptile-apps Bot commented Aug 19, 2026

Copy link
Copy Markdown

Acknowledged. From a code review standpoint the diff is clean — the pool-root fix is correct and the e2e regression test covers the exact failure mode described. Nothing here touches workflows, secrets, or permissions.

CI approval for first-time fork contributors requires a repo owner (maintainer) to click "Approve and run workflows" on the Actions page or the PR. That's a GitHub security gate that can't be bypassed from the review bot side either.

Once Kun approves the runs and CI comes back green, the PR should be ready to merge.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: real CI is green on f648be2 (check + test on ubuntu/macos/windows). Ignoring no-mistakes on #51 only, since this PR predates that requirement.

@greptileai — please review. You already scored this head 4/5 (P2 only: redundant FindRepoRoot in getRunE). If nothing new is blocking, we will merge after the usual wait.

@kunchenguid

Copy link
Copy Markdown
Owner

No description provided.

@kunchenguid
kunchenguid merged commit 3fcd637 into kunchenguid:main Aug 19, 2026
5 of 6 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @thirdreplicator — really appreciate you taking the time on this.

@kunchenguid

Copy link
Copy Markdown
Owner

No description provided.

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.

3 participants