Skip to content

feat(git): show every child repository in the Git panel with a visible switcher - #1112

Merged
Menghuan1918 merged 1 commit into
omdsh-dev:devfrom
dragonnahs:feat/repo-switcher-chips
Nov 4, 2026
Merged

Menghuan1918 merged 1 commit into
omdsh-dev:devfrom
dragonnahs:feat/repo-switcher-chips

Conversation

@dragonnahs

Copy link
Copy Markdown
Contributor

What

工作区是「容器目录」(自身不是 Git 仓库,子目录各自是仓库)时,在 Git 面板(更改 / 提交图)顶部渲染一行仓库胶囊:每个已发现的根一个按钮,当前被钉住的那个高亮,点击即切换。

Why

子仓库探测(#607 落地的有界 BFS)、git.status.repositories 字段、以及 chooseRepo 的写操作路由都已经就位,缺的只有「看得见」这一层:

于是三项目的工作区看起来「只有一个仓库」——这正是本 PR 要修的现象。反过来说,本 PR 不新增任何探测或路由能力:repoChoices 来自既有快照,点击复用既有 chooseRepo。

Changes

  • src/client/changes/GitLens.tsx
    • 新增模块级 rootKey() / sameRepoRoot():git rev-parse 给正斜杠、客户端状态可能拿到反斜杠、Windows 折叠大小写、尾分隔符同义——两种写法必须算同一个检出,否则「当前项」一个都标不亮。
    • 在「更改」区块之前渲染 div[data-scm-repos](仅 repoChoices.length > 1):每个根一个 button[data-scm-repo="<绝对路径>"],[data-active="true"] + aria-pressed 标记当前根,title 给绝对路径;点击调用 chooseRepo(root),读数、写操作与提交图继续被钉在该根上。
    • 单一仓库工作区不渲染这一行(不占高度、不改既有版式);原「⋯ → 仓库」菜单保持不变,两个入口并存,没有行为删除。
  • src/client/changes/changes.module.css
    • 新增 .repoSwitcher / .repoChip:视觉值全部走 --dsw-alias-* 令牌,11px / 22px 尺度沿用本面板既有约定;根多时横向滚动而不是换行,避免把「更改」推离顶部。
  • tests/git-repo-switcher.spec.tsx(新文件,3 例)
    • 多根逐个列出、data-active 只在当前根上、点击后下一次 git.status 的 repoRoot 是点中的根、切换后胶囊仍在;
    • 同一检出的 C:\WORK\ 与 C:/work 只标一个当前项;
    • 单仓库工作区不渲染该行,且「更改」区块仍在。
  • CHANGELOG.md / CHANGELOG_EN.md:补「未发布 / Unreleased」条目。

没有新增 i18n key(复用既有 gitRepository 作为该行的 aria-label),没有新增 host 路由或 git 命令,没有第二套轮询器。

Verification

本机(Windows,--maxWorkers=1):

  • pnpm exec vitest run tests/git-repo-switcher.spec.tsx tests/git-scm.spec.tsx tests/theme.spec.ts → 3 files / 30 tests 全绿(含新增 3 例)。
  • pnpm typecheck → 通过;pnpm lint → 通过;pnpm build → 通过(client bundle 正常产出)。
  • tests/git-graph.spec.ts 在本机单独跑时有一条与本改动无关的超时(truncates tags at their own limit…,该用例要创建大量 tag,本机 Git 2.56 + 慢盘 30 s 超时),Git 面板渲染路径不被它覆盖。

未附截图:本机没有安装上游 dev 的宿主 profile,无法给出真实面板截图;tests/git-repo-switcher.spec.tsx 用 jsdom 钉住了 DOM 契约([data-scm-repos] / [data-scm-repo] / [data-active])。

Notes

  • 按仓库分支模型(功能进 dev,main 只收发版),base 是 dev。
  • 若维护者更希望只保留菜单入口、把切换器做成下拉或折进「更改」标题行,形态可以按你们的偏好改;这一版刻意选「一眼看全」的一行胶囊,并在单仓库时完全消失。
  • 一个已知取舍:同名的两个子仓库(a/web、b/web)在胶囊上会重名,title 里是绝对路径——如果需要,我可以改成重名时显示工作区相对路径。

…e switcher

A container workspace (a project directory that is not itself a repository)
can hold several independent repositories. Discovery and `git.status`
already report all of them; the panel listed them only in the
"more actions -> repository" submenu, so nothing on screen said the others
existed and the body silently rendered repositories[0].

Render one chip per discovered root above the Changes section, mark the
root the panel is pinned to, and switch through the existing chooseRepo so
reads, mutations and the commit graph follow the selection. A single
repository workspace renders no row; the menu entry stays.
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.

2 participants