Skip to content

Preserve selected subfolder when Add Project imports a monorepo path - #6362

Closed
rodboev wants to merge 5 commits into
stablyai:mainfrom
rodboev:pr/preserve-add-project-subfolder
Closed

rodboev wants to merge 5 commits into
stablyai:mainfrom
rodboev:pr/preserve-add-project-subfolder

Conversation

@rodboev

@rodboev rodboev commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

When Add Project imports a folder inside a larger Git worktree, Orca currently stores that child path as the repo path, then snaps the project back to the real worktree root during authoritative worktree resolution. The result is a mismatched import identity and a first terminal that lands at the repo root instead of the folder the user picked.

This change fixes both sides of that flow:

  1. Canonicalize local Git imports to the actual repo root, matching the existing SSH import behavior.
  2. Preserve the originally selected folder as a one-shot initial terminal cwd during the first default-checkout activation.
  3. Keep terminal file-link resolution scoped to each pane's actual cwd so the one-shot override does not leak into later panes, inherited splits, or orphan-tab reuse.

The project stays Git-rooted for worktree, file-tree, and source-control behavior. Only the initial terminal landing context changes.

Closes #6336.

No visual change

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Focused validation completed in this session:

  • pnpm exec vitest run --config config/vitest.config.ts src/main/git/repo-detection.test.ts src/main/ipc/repos-remote.test.ts src/renderer/src/components/sidebar/AddProjectFromFolderDialog.test.tsx src/renderer/src/components/sidebar/project-added-default-checkout.test.ts src/renderer/src/lib/worktree-activation.test.ts src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.test.ts src/renderer/src/components/terminal-pane/terminal-link-handlers.test.ts
  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/terminal-link-handlers.test.ts src/renderer/src/store/slices/store-cascades.test.ts
  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.test.ts src/renderer/src/components/terminal-pane/terminal-link-handlers.test.ts src/renderer/src/store/slices/store-cascades.test.ts
  • pnpm run typecheck:node
  • pnpm run typecheck:web
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

AI Review Report

  • Cross-provider and same-family review passes traced local Git root canonicalization, selected-path handoff, one-shot tab cwd queueing, pane-scoped terminal link cwd resolution, split-pane inherited cwd seeding, and orphan-tab cleanup.
  • The review loop caught three renderer-side cwd leaks on the way to the final branch state: later-pane link resolution after the one-shot override, orphan-tab reuse of queued cwd state, and split-pane link seeding before OSC 7 confirmation. Each is now covered by focused regression tests.
  • Path containment and canonicalization stayed on the shared normalization helpers so Windows path casing and separator differences remain aligned with existing code paths.
  • Local and SSH imports still converge on the same repo-root identity, and repo-root picks plus non-Git folder imports keep their current behavior.

Security Audit

  • The selected-path override must only apply when the selected path is inside the activated worktree.
  • The terminal cwd override must stay data-driven; no shell command injection or startup cd command.
  • Pane-scoped cwd caches must clear when tabs or orphan panes are removed so stale paths cannot affect later terminals.
  • Local Git-root resolution must preserve bare-repo behavior and fail cleanly for invalid paths.

Notes

This keeps contained Git imports as Git projects. It does not convert them into folder workspaces, and it does not persist the selected subfolder beyond the first activation-created terminal. The final branch also tightens pane-scoped file-link cwd handling so later panes, inherited splits, and orphan-tab replacement do not reuse a stale one-shot cwd.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e45271d1-e289-4383-a62c-4fb01cc9fe15

📥 Commits

Reviewing files that changed from the base of the PR and between 629e1cfe955c37494143d221f86340366b1e48a9 and 43b6476.

📒 Files selected for processing (12)
  • src/main/git/repo-detection.test.ts
  • src/main/git/repo.ts
  • src/main/ipc/repos-remote.test.ts
  • src/main/ipc/repos.ts
  • src/renderer/src/components/sidebar/AddProjectFromFolderDialog.test.tsx
  • src/renderer/src/components/sidebar/AddProjectFromFolderDialog.tsx
  • src/renderer/src/components/sidebar/project-added-default-checkout.test.ts
  • src/renderer/src/components/sidebar/project-added-default-checkout.ts
  • src/renderer/src/components/terminal-pane/terminal-link-handlers.test.ts
  • src/renderer/src/components/terminal-pane/terminal-link-handlers.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.test.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
💤 Files with no reviewable changes (8)
  • src/renderer/src/components/sidebar/AddProjectFromFolderDialog.tsx
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.test.ts
  • src/renderer/src/components/terminal-pane/terminal-link-handlers.ts
  • src/renderer/src/components/sidebar/AddProjectFromFolderDialog.test.tsx
  • src/renderer/src/components/sidebar/project-added-default-checkout.test.ts
  • src/renderer/src/components/terminal-pane/terminal-link-handlers.test.ts
  • src/renderer/src/components/sidebar/project-added-default-checkout.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/main/git/repo.ts
  • src/main/ipc/repos.ts
  • src/main/ipc/repos-remote.test.ts

📝 Walkthrough

Walkthrough

The PR adds git-root resolution for local repositories and uses the resolved root when adding local git repos. It also threads a selected folder path through project-add completion into default-checkout activation, queues an initial CWD for the primary terminal tab, clears queued values during tab cleanup, and uses per-pane CWD resolution for terminal file-link handling.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.76% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main user-facing change: keeping the selected subfolder when importing a monorepo path.
Description check ✅ Passed The description includes all required sections and is substantially complete, with only minor detail gaps in the AI review report.
Linked Issues check ✅ Passed The changes implement the issue's selected-subfolder terminal behavior while keeping Git-rooted worktree resolution.
Out of Scope Changes check ✅ Passed The added terminal, worktree, and store changes are all tied to the selected-subfolder import fix.

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

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

@rodboev
rodboev force-pushed the pr/preserve-add-project-subfolder branch from 629e1cf to 43b6476 Compare June 27, 2026 05:48
nwparker added a commit that referenced this pull request Jun 28, 2026
…e first terminal in the subfolder (#6336) (#6574)

Add Project → Browse folder on a monorepo subfolder (e.g. /tmp/monorepo/packages/web)
stored the subfolder as Repo.path because isGitRepo() uses
`git rev-parse --is-inside-work-tree`, which is true for any subdirectory.
Authoritative worktree resolution then snapped activation back to the repo root,
so the import identity mismatched and the first terminal landed at the repo root
rather than the selected subfolder.

Canonicalize local git imports to the actual repo root via getGitRepoRoot()
(mirroring the SSH import path that snaps to check.rootPath, including its
post-resolution dedup), and preserve the user-selected subfolder as a one-shot
initial terminal cwd consumed only by the first activation-created pane.
Selecting the repo root applies no override, and re-importing a subfolder of an
existing project dedupes.

Supersedes community PR #6362.

Fixes #6336

Co-authored-by: Rod Boev <[email protected]>
@nwparker

Copy link
Copy Markdown
Contributor

Thank you for this fix, @rodboev! 🙏 Your approach — canonicalizing local Git imports to the repo root and preserving the selected subfolder as a one-shot initial terminal cwd — was exactly right.

I took this over to rebase it onto current main (which had moved ~50 commits and introduced conflicts in worktree-activation.ts and the terminal-pane lifecycle tests) and to fix one defect: the getGitRepoRoot worktree-root test asserted against a non-canonicalized tmp path, which fails on macOS where --show-toplevel resolves the /var → /private/var symlink.

That landed in #6574, which has now been merged to main and closes #6336. You're credited as co-author on the squash commit (Co-authored-by: Rod Boev), so the contribution is attributed to you.

Closing this one as superseded by #6574 — but the design and implementation here were yours. Thanks again for the thorough work, including the regression tests for the pane-scoped cwd leaks. 🐋

@nwparker nwparker closed this Jun 28, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…e first terminal in the subfolder (stablyai#6336) (stablyai#6574)

Add Project → Browse folder on a monorepo subfolder (e.g. /tmp/monorepo/packages/web)
stored the subfolder as Repo.path because isGitRepo() uses
`git rev-parse --is-inside-work-tree`, which is true for any subdirectory.
Authoritative worktree resolution then snapped activation back to the repo root,
so the import identity mismatched and the first terminal landed at the repo root
rather than the selected subfolder.

Canonicalize local git imports to the actual repo root via getGitRepoRoot()
(mirroring the SSH import path that snaps to check.rootPath, including its
post-resolution dedup), and preserve the user-selected subfolder as a one-shot
initial terminal cwd consumed only by the first activation-created pane.
Selecting the repo root applies no override, and re-importing a subfolder of an
existing project dedupes.

Supersedes community PR stablyai#6362.

Fixes stablyai#6336

Co-authored-by: Rod Boev <[email protected]>
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.

[Bug] Add Project → Browse folder imports a monorepo subfolder but opens the Git repository root

3 participants