Repository navigation
feat(git): 支持工作区根目录为 Git 仓库时仍探测并展示子目录独立仓库 - #607
Merged
Merged
Conversation
Contributor
Author
后续更新:二/三层嵌套子仓库发现(有界深度 BFS)真机使用中发现 v1( 根因两个事实叠加,depth ≥ 2 的仓库结构性不可见:
改动将一层扫描替换为有界深度 BFS dirent 扫描:
测试新增两个用例(
验证结果:
性能实测复刻典型复合工作区(根仓库 + 二/三层嵌套仓库,访问深度 ≤ 3 的目录约 336 个):
|
iasiv5
force-pushed
the
feat/discover-nested-repos
branch
from
October 10, 2026 00:22
68d6f22 to
4172de1
Compare
Contributor
Author
状态更新(2026-10-10):已 rebase 到最新 main
|
v1 只扫描 cwd 下一层目录,且每个子目录用 `git rev-parse --show-toplevel` 解析——该命令只沿父目录向上找 toplevel、从不向下探测,因此复合工作区根 目录下嵌套两层及以上的独立仓库(如 group/project、group/project/vendor-lib) 结构性不可见。 将一层扫描替换为有界深度 BFS: - 新常量 DISCOVERY_MAX_DEPTH = 4(BFS 层数):检出深度 = 层数 − 1 = 3, 覆盖三层嵌套;第 4 层 frontier 只收集、不再展开,成本被深度 ≤ 3 的 目录数约束。 - 每个访问目录只做一次 readdir,以 dirent 的 `.git` 存在性判定是否为 仓库(目录 / 文件 / symlink 三态,覆盖 worktree 与 submodule 的 `.git` 文件形态),子目录探测零 git 子进程——omdsh-dev#369 那种"数百个 git 子进程 串行卡死面板"的模式结构上不可能回归。 - 发现 .git 后仍继续下钻,非 submodule 的嵌入仓库(repo 套 repo)同样可见。 - 跳过隐藏目录、symlink 目录与 node_modules;每层保留 DISCOVERY_LIMIT 上限;pathIdentity 去重不变。 典型复合工作区(访问深度 ≤ 3 目录约 336 个)实测全部仓库根检出耗时约 12–17ms。
iasiv5
force-pushed
the
feat/discover-nested-repos
branch
from
October 14, 2026 00:39
4172de1 to
d311798
Compare
Contributor
Author
状态更新(2026-10-14):已再次 rebase 到最新 main,0.26.0 复核仍被需要
|
Menghuan1918
added a commit
that referenced
this pull request
Oct 16, 2026
…Nscientific-9) 冲突解决:删除 addLineCounts,状态读数改为分侧(staged/unstaged 各自一张表), 保留 dev 的 pathspec 化 numstat 读取(--literal-pathspecs + 原路径 + 行/字段上限)。 同批带上 #607 落地后暴露的两处适配: - discoverRepoRoots 的 BFS 发现根改走 realpath(macOS tmpdir 的 /var → /private/var 别名, 否则 rev-parse 的根与扫描根是同一仓库的两种拼法,dev 的 canonical() 断言当场红); - tests/git-worktree 的 numstat pathspec 用例按分侧形状断言(合计仍为 +3/−0)。
Menghuan1918
added a commit
that referenced
this pull request
Oct 16, 2026
macOS 的 tmpdir 是软链(/var → /private/var),Windows 上 join 出的是反斜杠而 `rev-parse --show-toplevel` 用正斜杠:两种拼法都会让同一个检出在仓库选择器里出现两次, CI 的 canonical() 断言先红。发现根现在走 realpath +(Windows 才做的)分隔符折叠。 在 5b6f731 的 ci-windows 上实测到 5 条 git.spec.ts 失败(全是分隔符)。
Collaborator
|
已合入 dev(合并提交 15665f1)。你的 BFS 保持原样,另补一处路径拼法归一:发现根走 realpath +(仅 Windows)分隔符折叠——否则同一个检出会以「扫描 join」与「rev-parse 的 realpath + 正斜杠」两种拼法出现两次,ci-windows 上 5 条 git.spec.ts 就是这么红的。感谢! |
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.
What
在「文件变动(Git 视角)」的仓库探测逻辑中做两件事:
group/project、group/project/vendor-lib这类二/三层嵌套的独立仓库同样能被发现。Why
在多项目复合工作区场景中,开发者常将根工作区初始化为一个顶层 Git 仓库(管理公共配置、工作区全局索引或跨项目文档),同时在子目录下存放多个各自拥有独立
.git的业务/插件代码库,且嵌套结构常达两~三层:try { return [await directRepoRoot(cwd)] } catch { 扫描子目录 }在根目录有.git时立即返回[cwd],repositories.length === 1,前端仓库切换下拉(GitLens.tsx的status.repositories.length > 1判定)被完全隐藏。git rev-parse --show-toplevel(只沿父目录向上找 toplevel,从不向下)也无法发现嵌套在普通容器目录之下的仓库——对group/这类目录调用 rev-parse 永远不会向下探测。Changes
src/git.tsdiscoverRepoRoots(cwd):try块不再短路返回;子目录扫描改为有界深度 BFS:DISCOVERY_MAX_DEPTH = 4(BFS 层数,检出深度 = 层数 − 1 = 3;第 4 层 frontier 只收集不展开);.git存在性判定(目录 / 文件 / symlink 三态,覆盖 worktree 与 submodule),不产生任何子 git 进程;rev-parse仅保留给 cwd 一次;.git后仍继续下钻,使非 submodule 的嵌入仓库(repo 套 repo)可见;node_modules;每层DISCOVERY_LIMIT上限;pathIdentity去重、repoRootsCacheTTL 缓存与 in-flight promise 合并。tests/git.spec.tsdiscovers root and direct child repositories when root is also a git repository保持不变;discovers nested child repositories up to three levels below a git root(三层嵌套 + worktree.git文件形态 +status()断言);descends into discovered repositories and skips hidden, node_modules and beyond-cap depths(嵌入仓库可见 /node_modules内不可见 / depth 4 不可见)。兼容性与边界
.git,roots.length === 1,下拉保持隐藏,与原先完全一致;.git):catch静默后照常 BFS,行为与原先一致;node_modules内、隐藏目录内、symlink 目标内的仓库按设计不可见(防止失控扫描);readdir,零子 git 进程;[BUG] 开启「源代码管理」面板后整个侧边栏卡死,重启后自动恢复该面板继续卡死,无法关闭或切换 #369 的"数百个 git 子进程串行卡死面板"模式结构上不可能回归。实测典型复合工作区(深度 ≤ 3 目录约 336 个)检出耗时 12–17 ms。验证
pnpm typecheck✅pnpm lint✅pnpm build✅pnpm vitest run tests/git.spec.ts✅(15/15,含新增测试)pnpm test:1332 通过,唯一失败tests/smoke.spec.ts > pages the log lazily with skip/count在基线 commit 上同样失败(既有问题,与本 PR 无关);