Fix serve crashing when run from a git worktree#3211
Conversation
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>
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches✨ Simplify code
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. Review rate limit: 0/1 reviews remaining, refill in 13 minutes and 52 seconds.Comment |
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.