feat(git): 支持工作区根目录为 Git 仓库时仍探测并展示子目录独立仓库 - #607
Open
iasiv5 wants to merge 1 commit into
Open
Conversation
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 视角)」的仓库探测逻辑中,解除「若当前工作区根目录是 Git 仓库则立即短路返回」的限制。改为:将根仓库加入探测列表后,继续向下扫描一层直接子目录,若子目录中存在独立的 Git 仓库则一并发现并去重收集。
Why
在多项目复合工作区场景中,开发者常将根工作区初始化为一个顶层 Git 仓库(用于版本管理公共配置、工作区全局索引、任务记录或跨项目基础设施文档),同时在子目录下存放多个各自拥有独立
.git的业务/插件代码库:discoverRepoRoots的逻辑是try { return [await directRepoRoot(cwd)]; } catch { ...扫描子目录... }。只要根目录有.git,便立即短路返回[cwd]。这导致repositories.length === 1,前端侧边栏顶部的仓库切换下拉选择器(GitLens.tsx的status.repositories.length > 1判定)完全被隐藏,开发者无法在侧边栏内查看和切换子项目的 Git 变动与提交历史,只能看到外层根目录的 Git 状态。Changes
src/git.tsdiscoverRepoRoots(cwd):解除try块的短路返回,改为将根仓库放入roots数组后,继续扫描一层子目录(保留原先跳过.开头隐藏目录、node_modules以及数量上限DISCOVERY_LIMIT的保护逻辑);pathIdentity去重与后续基于repoRootsCache的并发防抖与缓存机制。tests/git.spec.tsdiscovers root and direct child repositories when root is also a git repository:模拟根目录与子目录同时被git init初始化的工作区,断言repoRoots()与status()能准确返回两层仓库路径。兼容性与边界
.git,roots.length === 1,下拉菜单保持隐藏,行为与视觉与原先完全一致,无任何回归。.git):catch静默处理,原样扫描并发现子目录仓库,行为与原先完全一致。repoRootsCache缓存与 in-flight promise 复用,无额外开销。验证
pnpm typecheck✅pnpm lint✅pnpm test tests/git.spec.ts✅(13/13 包含新增多层仓库发现测试全部通过)pnpm build✅