Skip to content

fix(dev): do not treat a main checkout's separate Git directory as a linked worktree - #45442

Open
saphid wants to merge 3 commits into
pingdotgg:mainfrom
saphid:hunter/c-619538d033
Open

saphid wants to merge 3 commits into
pingdotgg:mainfrom
saphid:hunter/c-619538d033

Conversation

@saphid

@saphid saphid commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Problem

A main checkout whose separate Git directory sits under a folder named worktrees was treated as a linked worktree, so it got a checkout-local .t3 home instead of the normal one. The detector only checked whether the .git file's gitdir: ended in worktrees/<name>, and git init --separate-git-dir can produce that path too.

Deterministic repro on origin/main (27c4aad697f98c0fcda026e2167ac6966a3c1c15):

cd "$(mktemp -d)" && mkdir worktrees
git init -q --separate-git-dir "$PWD/worktrees/main" "$PWD/main"
git -C main rev-parse --path-format=absolute --git-dir --git-common-dir   # prints the same <tmp>/worktrees/main twice

Then call resolveWorktreeT3Home("<tmp>/main") from @t3tools/shared/devHome. The regression test in packages/shared/src/devHome.test.ts does exactly this.

  • Observed: it returns <tmp>/main/.t3.
  • Expected: it returns undefined, the same as any other main checkout.

Change

When the path matches worktrees/<name> and the Git directory exists, resolveGitWorktreePath now also requires Git's commondir file. Git writes that file for every linked worktree, including worktrees of bare repositories and custom common dirs. If the Git directory can't be read, the code still treats the checkout as a linked worktree, so a real worktree can't fall through to the live home.

All callers share this resolver, so such a checkout now gets main-checkout behavior everywhere:

  • The dev runner (home and ports) and t3 pair discovery fall back to the normal home.
  • migrate-dev-db without --base-dir stops with its existing "not in a worktree" error.
  • Storage cleanup no longer limits itself to the dev home's own worktrees directory.

Scope

Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.

Verification

  • New regression test ignores a main checkout whose separate Git directory is under worktrees uses real git init --separate-git-dir. It first asserts that Git's git-dir and common-dir match, then that resolveWorktreeT3Home returns undefined. On base it fails with expected '<tmp>/main/.t3' to equal undefined; on head it passes.
  • New test finds a real linked worktree whose Git directory exists runs a real git worktree add --detach and passes on both base and head, so linked-worktree detection is unchanged. The existing bare-repo and custom common-dir worktree tests still pass.
  • Both real-Git fixtures ignore your global and system Git config (GIT_CONFIG_GLOBAL=/dev/null, GIT_CONFIG_NOSYSTEM=1). The file also passes under a hostile global config (commit.gpgsign=true with a failing gpg.program, init.defaultBranch=linked).
  • vp run check:changed exited 0 on HEAD 2922e4d73fea62231cdd906b75d0f24e64540fc6 (format, lint, knip, typecheck, tests).
  • Evidence (before/after resolver output, base test failure, HEAD check summary): https://gist.github.com/saphid/9b2a98112e6468f1bca70e2a64933d75

Not shown: I only ran the resolver itself, not the code that calls it. I did not run a dev server, t3 pair, migrate-dev-db, storage cleanup or a scenarios:prove scenario inside such a checkout; I only read their code. Also not shown: Windows paths, and linked worktrees whose Git directory can't be read (those still count as linked worktrees, which is today's behavior).

Authored by Claude Opus 5.5 (Model Hub); reviewed by GPT-6.2 Sol (Codex).

Not shown

  • .github/pull_request_template.md:24 — ADVISORY: The linked gist shows the resolver before/after and the base assertion failure, but not the HEAD check summary it is cited for. Add the HEAD summary to the gist or remove that claim from the evidence link description.

@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Nov 29, 2026
@macroscopeapp

macroscopeapp Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs Human Approval

Macroscope's review found this PR requires human approval — The fix distinguishes separate Git directories from linked worktrees, but also changes affected checkouts from local .t3 state to the environment/shared home by default. Confirm that this database-target transition is intended, including for pairing commands that may run migrations.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The worktree resolver identifies linked-worktree Git directories by path structure, then checks the resolved Git directory and its commondir file. Tests cover a linked worktree and a main checkout with a separate Git directory.

Changes: Worktree resolution

Layer / File(s) Summary
Git directory detection, validation, and tests
packages/shared/src/devHome.ts, packages/shared/src/devHome.test.ts
The detector returns a nonempty gitdir path when its normalized segments match the linked-worktree path structure. The resolver checks the resolved Git directory and its commondir file. Tests cover a linked worktree and a main checkout with a separate Git directory.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to a14af

The change stops a main checkout whose separate Git directory sits under a worktrees directory from being treated as a linked worktree. It is covered by a regression test and has a safe fallback, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the actual change: a main checkout whose separate Git directory sits under a worktrees path should no longer be treated as a linked worktree. It follows the conventional commit form …
Description check Passed The description follows the template sections (Problem, Change, Scope, Verification). It explains the bug, gives a deterministic reproduction, describes the resolver change and its effect on callers, …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the actual change: a main checkout whose separate Git directory sits under a worktrees path should no longer be treated as a linked worktree. It follows the conventional commit form and is specific to the fix. The title is 84 characters, which is longer than ideal but still readable.

Full details: Description check

Explanation

The description follows the template sections (Problem, Change, Scope, Verification). It explains the bug, gives a deterministic reproduction, describes the resolver change and its effect on callers, and states why no issue is needed. The Verification section reports focused tests, real-Git fixtures, and a check run, and it lists what was not tested. The template's "Change" section asks for an explanation of cross-component changes, and the description covers this through the caller list. A reviewer advisory notes that the linked gist does not show the HEAD check summary cited in the evidence. The author should either add that summary to the gist or remove the claim.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 1c81e42 and a14af33.

Files selected for processing: 2

  • packages/shared/src/devHome.test.ts
  • packages/shared/src/devHome.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Nov 29, 2026
@juliusmarminge

Copy link
Copy Markdown
Member

Evidence

Linux x86_64, real dev server, fresh databases, no seed. On both commits, clone with a separate Git directory at <metadata>/worktrees/main, confirm Git directory equals common directory and no commondir, install dependencies, then launch the exact dev:server script with disposable T3CODE_HOME and T3CODE_DEV_SEED=0. Wait for Listening and inspect persisted files after shutdown. Private paths are replaced with placeholders in these captured runtime transcripts.

Before After
54a42b22f4 a14af33056
Before: separate main checkout incorrectly uses worktree state After: separate main checkout honors T3CODE_HOME and default ports
source=worktree, ports 15971/7931; database in checkout-local .t3; disposable home empty. source=default ports, ports 13773/5733; database in disposable home; no checkout-local userdata.

Genuine linked-worktree controls retain isolated defaults on base and head.

Driver · Before transcript · After transcript

Not shown:

  • Relative .git pointers and missing/unreadable Git metadata were not exercised; this proof covers the reported absolute separate Git directory and genuine linked worktrees. The optional Git-directory relocation control was not repeated.

@juliusmarminge juliusmarminge added takeover:needs-julius Takeover done; route gate says Julius decides and removed takeover:in-progress A takeover lead is working on this PR labels Nov 29, 2026

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

size:S 10-29 changed lines (additions + deletions). takeover:needs-julius Takeover done; route gate says Julius decides vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants