Skip to content

fix: stop current-Project resolution at the Git checkout boundary - #521

Open
clvsh wants to merge 2 commits into
mainfrom
fix/worktree-project-resolution
Open

clvsh wants to merge 2 commits into
mainfrom
fix/worktree-project-resolution

Conversation

@clvsh

@clvsh clvsh commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Why

Closes #516.

Commands that resolve "the current Project" picked the nearest linked ancestor by path prefix. Claude Code creates worktrees inside the repository at .claude/worktrees/<name>. Until PV links such a worktree, which waits for any approved prepare hook, a command run there resolved to the main checkout's Project:

  • pv unlink unlinked it and, through the source rule, every discovered worktree;
  • pv php:use wrote the main checkout's pv.yml;
  • pv project:env printed the main Project's database name and credentials;
  • the php and composer shims used the main Project's PHP track.

Change

  • state::fs::git_checkout_root finds the nearest directory with a .git entry. A directory marks a main checkout; a file marks a linked worktree or a submodule.
  • Database::nearest_project_for_path drops candidate Projects above that root. All callers get the fix: unlink, project:env, open, php:use and the shims.
  • When nothing resolves inside a checkout nested in a linked Project, the new CliError::ProjectNotLinkedInCheckout names the checkout and points at pv jobs and pv status. Elsewhere the existing ProjectNotResolved message is unchanged.
  • The shims need no new rule. An unlinked worktree is now "outside a linked Project", so they use the global default track (DESIGN.md already says so).
  • DESIGN.md: Opening Projects states the boundary rule; Project Linking points to it.

Decisions taken, as proposed in #516:

  • An unlinked worktree behaves like any unlinked directory. It gets no special PHP selection.
  • Every nested checkout stops resolution, including submodules and nested repositories, not only worktrees. One rule, no parsing of gitdir. One consequence: running php inside a Composer --prefer-source package under vendor/ now uses the global default track instead of the Project's.
  • Directories outside any Git checkout resolve as before.

Tests

  • nearest_project_resolution_stops_at_the_git_checkout (state) covers:
    • a main-checkout subdirectory;
    • a monorepo member;
    • a nested worktree, a submodule and a nested repository, which resolve nothing;
    • a non-Git Project;
    • the worktree once its own Project is linked.
  • commands_in_an_unlinked_worktree_inside_a_project_do_not_resolve_that_project (cli, insta snapshot): unlink, project:env and non-interactive open fail with the new message and leave the main Project linked.
  • Both new tests fail with the boundary filter removed.
  • End-to-end with the debug binary and real git worktree add: the fix: commands run inside an unlinked Git worktree act on the main checkout's Project #516 reproduction now errors instead of unlinking main, and a monorepo member still resolves from its src/.
  • cargo nextest run --workspace --profile ci (macOS arm64): 1121 passed, 17 skipped.
  • cargo fmt --all and cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean.

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 30 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: QUIET
  • Plan: Advanced
  • Run ID: 64702483-df58-42cc-8b54-d45c4576b45b
Commits

Reviewing files that changed from the base of the PR and between 617631a and a6a5e5c.

Files ignored due to path filters: 1

  • crates/cli/tests/it/snapshots/it__project_unlink__commands_in_an_unlinked_worktree_inside_a_project_do_not_resolve_that_project.snap is excluded by !**/*.snap
Files selected for processing: 9

  • DESIGN.md
  • crates/cli/src/commands/mod.rs
  • crates/cli/src/commands/php.rs
  • crates/cli/src/commands/project.rs
  • crates/cli/src/error.rs
  • crates/cli/tests/it/project_unlink.rs
  • crates/state/src/database.rs
  • crates/state/src/fs.rs
  • crates/state/tests/state_foundation.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T03:30:26.574948Z 8887f74 New commits
🔒 Security Review ✅ Completed 2026-11-20T02:44:55.523059Z 6a56ecf PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codspeed

codspeed Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 7 untouched benchmarks


Comparing fix/worktree-project-resolution (a6a5e5c) with main (617631a)

Open in CodSpeed

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ Checkout isolation looks correct; one minor diagnostic suggestion inline.

Approach: sound — bounding the shared resolver protects all current-Project callers without parsing Git metadata.

Reviewed changes Reviewed checkout isolation, its command and shim callers, diagnostics, and regression coverage.

  • Checkout boundaries: excludes enclosing Projects across worktree, submodule, and nested-repository boundaries while preserving monorepo and non-Git resolution.
  • CLI and shims: adds checkout-specific errors and preserves global PHP fallback and explicit Project selection.
  • Design and tests: updates the documented contract and adds state/CLI regressions; all 78 state-foundation tests, 5 unlink integration tests, and formatting checks passed locally.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-6.1-sol | 𝕏

Comment thread crates/cli/src/error.rs Resolved
Commands that resolve a Project from the current directory picked the
nearest linked ancestor by path prefix. Inside a Git worktree nested in a
linked Project, such as Claude Code's `.claude/worktrees/<name>`, a command
run before PV linked the worktree acted on the main checkout's Project:
`pv unlink` unlinked it and its discovered worktrees, `pv php:use` edited its
`pv.yml`, and `pv project:env` printed its database credentials.

Resolution now stops at the root of the Git checkout holding the current
directory. A Project above that root never matches, so worktrees,
submodules and nested repositories resolve only Projects linked inside
them. Commands that need a Project name the unlinked checkout, and the PHP
and Composer shims use the global default track there, as outside any
linked Project.

Closes #516
@clvsh
clvsh force-pushed the fix/worktree-project-resolution branch from 6a56ecf to 8887f74 Compare November 20, 2026 03:28
Submodules, nested repositories and opted-out worktrees never get
automatic setup, so the unlinked-checkout error also names `pv link`.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes Reviewed the checkout diagnostic update since the prior review.

  • Added manual recovery guidance: included pv link for checkouts without automatic setup, addressing the earlier suggestion.
  • Updated the diagnostic snapshot: verified the new output; all 5 project_unlink integration tests passed.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

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.

fix: commands run inside an unlinked Git worktree act on the main checkout's Project

1 participant