Skip to content

【已审核】feat(git-diff): 文件改动 tab 仓库选择器——按仓库聚合所有 worktree 变更与分支对比 - #1432

Closed
climashscape wants to merge 1 commit into
proma-ai:mainfrom
climashscape:feat/git-repo-selector
Closed

【已审核】feat(git-diff): 文件改动 tab 仓库选择器——按仓库聚合所有 worktree 变更与分支对比#1432
climashscape wants to merge 1 commit into
proma-ai:mainfrom
climashscape:feat/git-repo-selector

Conversation

@climashscape

@climashscape climashscape commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

概述

右侧边栏「文件改动」tab 在包含大量 Git 仓库的项目根(monorepo / fork 集合)下存在两个痛点:所有仓库的改动混杂显示无法聚焦;主仓库的 git worktree 分支改动(.worktrees/ 下)默认扫描不到。

本 PR 引入仓库选择器:把工作区扫描到的 Git 仓库加入下拉并绑定会话,选中后该会话只扫描此仓库的所有 worktree(含 main 与各分支 worktree),以聚合视图展示未提交改动 + 领先/落后 commit 概览;支持仓库内单 worktree 细化、分支间对比(A vs B)、手动添加仓库、基准分支自动探测。同时以 merge 形式包含 perf/git-diff-parallel-cache(PR #1424)的扫描性能优化作为基础设施。

改动

  • apps/electron/src/main/lib/git-diff-service.ts(+831):新增 listRepos / getRepoChanges / listWorktreesFromRoot / resolveDefaultBaseBranch(单次 for-each-ref + 30s 缓存);findAllGitRootsDown 区分 .git 目录与 worktree 指针文件;默认 getUnstagedChanges 枚举 worktree;多级缓存 + 定向失效
  • apps/electron/src/main/ipc.ts:新增 git:list-repos / git:get-repo-changes / shell:select-directory,逐 worktree 路径授权、缓存 key 会话隔离
  • apps/electron/src/preload/index.ts:electronAPI 新增 listRepos / getRepoChanges / selectDirectory
  • packages/shared/src/types/runtime.ts:新增 RepoInfo / RepoChangesResult / RepoWorktreeChanges / CommitSummary 类型与 3 个 IPC 通道
  • apps/electron/src/renderer/components/diff/RepoSelector.tsx(新增):仓库下拉选择器,绑定会话,支持手动添加仓库
  • apps/electron/src/renderer/components/diff/WorktreeSelector.tsx:改造为仓库内工作树过滤条,支持对比基准选择(A vs B 双向 commit 概览)
  • apps/electron/src/renderer/components/diff/DiffChangesList.tsx:聚合视图(worktree 分组 + 领先/落后 commit + 折叠/搜索)+ 单 worktree 细化视图切换;兼容上游 feat(agent): surface non-git file changes #1429 的 non-git 文件变更展示
  • apps/electron/src/renderer/atoms/agent-atoms.ts / SidePanel.tsx / LeftSidebar.tsx / useGlobalAgentListeners.ts / workspace-watcher.ts:per-session 选择状态、缓存清理、预览基准透传、写文件失效
  • apps/electron/src/main/lib/git-diff-service.test.ts(新增):临时仓库集成测试(发现/枚举/聚合/基准探测)

与 PR #1424 的关系(重要)

测试

  • bun run --filter=@proma/electron typecheck
  • build:main / build:preload / build:renderer
  • bun test 5 个集成用例全过(临时 git 仓库验证 findAllGitRoots / listRepos / worktree 枚举 / getRepoChanges 聚合 / 基准自动探测)
  • dev 实测:选中 Proma 仓库显示 5 个 worktree 聚合(分支/head/commits/文件统计)、单 worktree 细化、对比基准切换显示「基准独有 commits」、添加仓库对话框均正常

紧急度

常规

备注

仓库选择器(文件改动 tab 顶部):
- 扫描到的 Git 仓库加入下拉并绑定会话,选中后该会话只扫描此仓库的所有 worktree
- 仓库列表按 worktree 数优先排序,支持手动添加仓库(系统目录对话框)
- 工作树过滤条:聚合视图 ↔ 单个 worktree 视图切换

仓库聚合视图:
- 按 worktree 分组展示未提交改动 + 领先/落后 commit 概览(hash/作者/日期)
- 每个 worktree 显示 分支/head/±commits 徽章/改动统计,支持搜索与折叠
- 点击文件预览 diff,基准对齐自动探测结果

分支对比:
- 对比基准可选(默认自动探测 origin/main → origin/master → 本地 → HEAD~)
- 显式对比基准用两点 diff(两分支全部差异),并展示基准独有 commits(双向)

性能(合并 perf/git-diff-parallel-cache):
- 扫描并发预检(porcelain 快速跳过干净仓库)+ 六层缓存(scan/perRepo/gitRoots/
  worktrees/repoChanges/listRepos)+ 定向失效 + watcher 噪声过滤
- 仓库根发现/基准探测/工作树枚举均缓存;getRepoChanges 会话隔离缓存

修复:
- findAllGitRootsDown 将 worktree 目录(.git 指针文件)误识别为独立仓库
- 默认「会话改动」视图枚举 worktree,未提交改动直接可见
- Electron window.prompt 不可用(改系统对话框);跨会话缓存泄漏;定向失效
  不覆盖聚合缓存;选基准无效果(三点 diff 语义)等

测试:git-diff-service 集成测试(临时仓库验证发现/枚举/聚合/基准探测)
@climashscape
climashscape force-pushed the feat/git-repo-selector branch from d8cddce to 2fef994 Compare August 4, 2026 16:36
@climashscape
climashscape marked this pull request as ready for review August 4, 2026 19:17
@climashscape climashscape changed the title 【等待审核】feat(git-diff): 文件改动 tab 仓库选择器——按仓库聚合所有 worktree 变更与分支对比 【已审核】feat(git-diff): 文件改动 tab 仓库选择器——按仓库聚合所有 worktree 变更与分支对比 Aug 4, 2026
@climashscape

Copy link
Copy Markdown
Contributor Author

作者主动关闭(本地 build/long-term 维护流保留这些功能,不再向上游提交)。

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.

希望增加git组件和代码diff差异查看组件

1 participant