fix: support monorepo/multi-repo workspaces with nested git sub-projects#2369
Open
can2049 wants to merge 1 commit into
Open
fix: support monorepo/multi-repo workspaces with nested git sub-projects#2369can2049 wants to merge 1 commit into
can2049 wants to merge 1 commit into
Conversation
When opening a monorepo directory (a top-level directory containing
multiple git sub-projects), fresh failed to recognize sub-projects as
git repositories and all git-dependent features broke.
Root causes:
1. `editor.readDir()` did not follow symlinks — `.git` symlinks
pointing to directories were reported as is_dir=false.
2. Most plugins called `editor.spawnProcess("git", ...)` without an
explicit cwd, defaulting to the workspace root which is not itself
a git repo in monorepo setups.
3. Sub-repo discovery only scanned one level of subdirectories.
Fixes:
- quickjs_backend.rs: `read_dir` now uses `std::fs::metadata()` to
follow symlinks, correctly reporting is_dir for .git symlinks.
- file_operations.rs: `resolve_git_index` uses BFS (max depth 3) to
discover nested sub-repos when the workspace root is not a git repo.
- git_explorer.ts: recursive `discoverSubRepos()` (max depth 3) finds
git repos in nested directory structures.
- git_statusbar.ts: uses active buffer's directory for branch detection.
- git_blame.ts: passes file's directory as cwd for git blame/show.
- git_find_file.ts: uses active buffer's directory for git ls-files.
- git_log.ts: passes explicit cwd for git show.
- live_grep.ts: git-grep availability check falls back to active
buffer's directory.
- merge_conflict.ts: passes file directory as cwd for git show.
- code-tour.ts: passes explicit cwd for git rev-parse.
- audit_mode.ts: all ~20 git spawn calls now use state.repoRoot as cwd.
Co-authored-by: Cursor <cursoragent@cursor.com>
67e65cb to
fe9c1dd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When opening a workspace that is not itself a git repository but contains nested git sub-projects (monorepo/multi-repo layout), fresh failed to:
This PR fixes all git-related functionality to work correctly in monorepo setups.
Root Causes
Symlink handling in
readDir: Theeditor.readDir()backend usedstd::fs::DirEntry::file_type()which does not follow symlinks. In monorepos,.gitis often a symlink to the actual git directory — it was incorrectly reported asis_dir=false, preventing plugins from detecting git repos.Missing
cwdin git command execution: Most plugins callededitor.spawnProcess("git", args)without specifying acwdparameter, causing git commands to execute in the workspace root (which is not a git repo in monorepo setups). This caused all git operations to fail with "not a git repository" errors.Single-level sub-repo discovery: The file explorer and git index watcher only scanned immediate subdirectories. Multi-level structures like
workspace/group/project/were not discovered.Changes
Core (Rust)
quickjs_backend.rsread_dirnow follows symlinks viastd::fs::metadata()to correctly reportis_dirfor.gitsymlinksfile_operations.rsresolve_git_indexuses BFS with max depth 3 to discover nested sub-reposPlugins (TypeScript)
git_explorer.tsdiscoverSubRepos(dir, maxDepth=3)for multi-level repo discoverygit_statusbar.tsgetGitCwd()helper — prioritizes active buffer's directory for branch detectiongit_blame.tseditor.pathDirname(filePath)as cwd forgit blameandgit showgit_find_file.tsgit ls-filesgit_log.tsgit showlive_grep.tsmerge_conflict.tsgit show :0:pathcode-tour.tsgit rev-parseaudit_mode.tsstate.repoRoot || editor.getCwd()as cwdDesign Decisions
rev-parse --show-toplevel..gitboundaries (won't enter a git repo to find submodules — those are managed by git itself)..are skipped during discovery to avoid scanning.git,.cache,node_modulesetc.Test Plan
Made with Cursor