Skip to content

Fix serve crashing when run from a git worktree#3211

Merged
Mpdreamz merged 1 commit into
mainfrom
fix/git-worktree-scoped-filesystem
Apr 29, 2026
Merged

Fix serve crashing when run from a git worktree#3211
Mpdreamz merged 1 commit into
mainfrom
fix/git-worktree-scoped-filesystem

Conversation

@Mpdreamz
Copy link
Copy Markdown
Member

Why

Running `dotnet run --project src/tooling/docs-builder -- serve` from a git worktree checkout throws a `ScopedFileSystemException` and crashes immediately. Worktrees are a common workflow for contributors working on multiple branches simultaneously, so the serve command needs to work from them.

What

In a git worktree the `.git` entry is a file (not a directory) that points to the main repo's `.git/worktrees/` directory. `GitCheckoutInformation.Create` reads `config` and `HEAD` from the main repo's `.git` dir to determine branch and remote — but that directory lives outside the worktree root and was rejected by `ScopedFileSystem`.

`FileSystemFactory.RealGitRootForPath` now detects the worktree pointer file in both code paths (explicit `--path` arg and the default `WorkingDirectoryRoot`), resolves the main repo's `.git` directory two levels up from the `worktrees/` path, and adds it as an explicit scope root. The pre-built `RealRead` fast-path is preserved for the common non-worktree case.

RealGitRootForPath used to either return the pre-built RealRead (path=null)
or scope to FindGitRoot(path) — neither path accounted for git worktrees.

In a worktree the local .git entry is a file, not a directory, pointing to
the main repo's .git/worktrees/<name> directory. GitCheckoutInformation.Create
needs to read config and HEAD from the main repo's .git dir, which lives
outside the worktree root, causing a ScopedFileSystemException.

Fix: detect the worktree pointer file in both code paths, resolve the main
repo's .git directory (two levels up from the worktrees/<name> path), and
add it as an explicit scope root so reads are permitted.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@Mpdreamz Mpdreamz requested a review from a team as a code owner April 29, 2026 13:01
@Mpdreamz Mpdreamz added the bug label Apr 29, 2026
@Mpdreamz Mpdreamz requested a review from reakaleek April 29, 2026 13:01
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 29, 2026

Warning

Rate limit exceeded

@Mpdreamz has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 13 minutes and 52 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 5984bd68-f5fc-43be-9d8a-7b30e0da4194

📥 Commits

Reviewing files that changed from the base of the PR and between 8bd6f30 and 2702a5a.

📒 Files selected for processing (1)
  • src/Elastic.Documentation.Configuration/FileSystemFactory.cs
✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/git-worktree-scoped-filesystem

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 13 minutes and 52 seconds.

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

@Mpdreamz Mpdreamz merged commit dd6d8db into main Apr 29, 2026
25 checks passed
@Mpdreamz Mpdreamz deleted the fix/git-worktree-scoped-filesystem branch April 29, 2026 18:51
@cotti cotti mentioned this pull request Jun 3, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants