Skip to content

fix(server): keep separate Git metadata out of worktree paths - #12298

Closed
a3ylf wants to merge 1 commit into
pingdotgg:mainfrom
a3ylf:fix/separate-git-dir-worktree
Closed

a3ylf wants to merge 1 commit into
pingdotgg:mainfrom
a3ylf:fix/separate-git-dir-worktree

Conversation

@a3ylf

@a3ylf a3ylf commented Sep 17, 2026 •

Copy link
Copy Markdown

What Changed

Exclude the Git metadata directory from reusable worktree paths. Resolve the current branch's checkout from the caller's --show-toplevel result without storing that caller-specific path in the ref snapshot shared by linked worktrees.

Why

With --separate-git-dir, git worktree list can report the metadata directory as the main checkout. T3 accepted that existing directory and could reuse it for a thread, losing access to project files and local skills.

Fixes #12204.

Validation

  • Both new real-Git regressions fail on main and pass with this change. They cover external metadata with and without core.worktree, a nested project directory, and a ref cache first populated by a linked worktree.
  • 232 tests passed across GitVcsDriverCore, GitVcsDriver, and GitManager.
  • Server typecheck and scoped formatting/lint passed; lint reports one existing inline-schema warning outside the change.
  • Verified on Linux with Git 2.43.0. No desktop or mobile UI run.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • UI screenshots and interaction video are not applicable to this server-only change

Model: GPT-6. Harness: Codex.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected worktree path reporting for repositories that use separate Git metadata directories.
    • Improved current-branch detection for main and linked worktrees, including access through nested directories.
    • Prevented Git metadata paths from being incorrectly treated as reusable worktree locations.

Signed-off-by: Alexandre Rodrigues <alexandre3ylf@gmail.com>
@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Sep 17, 2026
@macroscopeapp

macroscopeapp Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at eff1bfe

Macroscope's review found this PR approvable — This small server-side fix prevents Git metadata directories from being reused as worktrees and keeps caller-specific checkout paths out of shared ref-cache data. The behavior is narrowly scoped and covered by targeted real-Git regression tests.

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

@coderabbitai

coderabbitai Bot commented Sep 17, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 41181c4d-9701-494f-be05-74dcdface10b

📥 Commits

Reviewing files that changed from the base of the PR and between 4749035 and eff1bfe.

📒 Files selected for processing (2)
  • apps/server/src/vcs/GitVcsDriverCore.test.ts
  • apps/server/src/vcs/GitVcsDriverCore.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The Git VCS driver now excludes separate Git metadata directories from reusable worktrees and reports the caller’s worktree root for the current branch. Tests cover nested checkouts, linked worktrees, and both core.worktree configurations.

Changes

Git worktree path handling

Layer / File(s) Summary
Separate Git directory filtering
apps/server/src/vcs/GitVcsDriverCore.ts
readGitRefsSnapshot no longer treats the shared Git directory as a reusable worktree. Other entries still require a successful path check.
Current worktree path resolution and coverage
apps/server/src/vcs/GitVcsDriverCore.ts, apps/server/src/vcs/GitVcsDriverCore.test.ts
listRefs uses the caller’s worktree root for the current branch. Tests cover separate Git directories with and without core.worktree, nested paths, and linked worktrees.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: t3dotgg

Merge Risk: ⚪ Minimal · up to eff1b

The updated Git worktree handling preserves the requested checkout path and avoids reusing separate metadata directories. No remaining merge-blocking risk was identified.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preventing separate Git metadata directories from being treated as worktree paths.
Description check ✅ Passed The description explains what changed, why it changed, and how it was validated. It includes the required checklist and correctly identifies the server-only scope, so UI evidence is not applicable.
Linked Issues check ✅ Passed The PR addresses #12204. readGitRefsSnapshot excludes the Git common metadata directory from reusable worktree paths. listRefs uses the caller's --show-toplevel result for the current checkout a…
Out of Scope Changes check ✅ Passed The changed production code and tests directly support #12204. The test additions verify the Git metadata and requested-folder behavior. No unrelated production behavior or unrelated files are shown i…
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

@a3ylf a3ylf closed this by deleting the head repository Sep 26, 2026
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). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Git dir followed unconditionally

1 participant