Skip to content

feat(Branches): 新增「清理已删远程分支」入口,解决 LOG 视图残留已删分支提交问题 - #44

Merged
ThreeFish-AI merged 2 commits into
feature/1.x.xfrom
ThreeFish-AI/hide-deleted-branch-commits
Jul 1, 2026
Merged

feat(Branches): 新增「清理已删远程分支」入口,解决 LOG 视图残留已删分支提交问题#44
ThreeFish-AI merged 2 commits into
feature/1.x.xfrom
ThreeFish-AI/hide-deleted-branch-commits

Conversation

@ThreeFish-AI

Copy link
Copy Markdown
Owner

背景

LOG 视图的 All 范围通过 git log --all 拉取提交,--all 会遍历 refs/heads/* + refs/remotes/* + refs/tags/*。当一个分支在远端被删除(如 GitHub PR 合并后删分支、队友删分支),但本地的远程跟踪引用 refs/remotes/origin/<branch> 未被 prune 时,--all 仍能经该陈旧引用遍历到那些提交——导致「已删除分支」的提交继续残留在 LOG 视图中。

git fetch 默认清理已消失的远程跟踪引用,需要显式 --prune

方案(复用驱动 + 最小干预)

  1. 新增 hyperGit.pruneRemotes 命令(Branches 视图工具栏,clear-all 图标):执行 git fetch --prune 清理陈旧 refs/remotes/*,使 LOG 的 All 范围反映真实远程状态。复用既有 repo.fetch({ prune: true }) 能力。
  2. 循证反馈:prune 前后对 refs/remotes 各快照一次,以 diffPrunedRefs 差集得出被清理的引用名并提示用户。规避 [deleted] 明细走 stderr 而 execGit 仅回传 stdout 的解析限制。
  3. 顺带修复刷新缺陷hyperGit.fetchhyperGit.deleteRemoteBranch 在改动引用后只刷新了 branchesTree,遗漏 logTree.refresh()logTree 已在作用域内),导致 LOG 不能即时反映引用变更。补齐后 prune / fetch / 删除远程分支均即时刷新 LOG。

改动文件

文件 说明
src/engine/ref/cleanup.ts 新增纯函数 diffPrunedRefs(before, after)(零 vscode 依赖,便于单测)
src/adapter/history-commands.ts 新增 pruneRemotes 命令 + listRemoteTrackingRefs 辅助;fetchlogTree.refresh()
src/adapter/remote-commands.ts deleteRemoteBranchlogTree.refresh()
package.json 注册命令 + Branches 视图工具栏菜单(1_sync@1.5,紧邻 Fetch)
tests/unit/ref-cleanup.test.ts diffPrunedRefs 单元测试(5 例)

验证

  • pnpm run check-types(tsc):通过
  • pnpm run lint(ESLint,CI 门禁):通过
  • node esbuild.js(打包):通过
  • pnpm run test:unit(vitest):306 / 306 全部通过(含新增 5 例)
  • 手动验证路径:Branches 工具栏点击「Prune Deleted Remote Branches」→ 提示清理了哪些引用 → LOG 立即刷新、已删分支独有提交消失。

非目标

  • 不新增「本地分支范围」LOG scope;
  • 不改 git log --all 构造;
  • 不引入已删分支持久化记录或删除线渲染(代码本就不存在此类渲染)。

🤖 Generated with Claude Code

- 新增 hyperGit.pruneRemotes 命令(Branches 视图工具栏,icon=clear-all):
  执行 git fetch --prune 清理陈旧 refs/remotes/* 跟踪引用,使 LOG 的 All 范围
  不再经其触达已删远程分支的提交(根因:分支在远端删除后本地跟踪引用未 prune)
- prune 前后对 refs/remotes 各快照一次,以 diffPrunedRefs 差集给出循证反馈,
  规避 [deleted] 明细走 stderr 而 execGit 仅回传 stdout 的解析限制
- 修复 hyperGit.fetch / hyperGit.deleteRemoteBranch 仅刷新 branchesTree、
  遗漏 logTree.refresh() 导致 LOG 不能即时反映引用变更的缺陷
- 补 diffPrunedRefs 纯函数单元测试(ref-cleanup)

🤖 Generated with [Claude Code](https://github.com/claude), [CodeX](https://openai.com), [Gemini](https://github.com/apps/gemini-code-assist)
Co-Authored-By: Aurelius Huang<threefish.ai@gmail.com>
pnpm/action-setup@v6(135f509 由 v4 升级引入)为破坏性变更:严格要求解析 pnpm 版本,
不再隐式回退 latest。原步骤序 action-setup 先于 checkout,致 package.json 未就绪、
无法读取 packageManager 字段,CI 在 setup 阶段即报 "No pnpm version is specified"。

将 actions/checkout 前置于 pnpm/action-setup,使其从检出的 package.json 读取
packageManager: pnpm@11.9.0(单一事实源,无需在 workflow 重复声明 version)。
lint-build / test / package / publish 四个 job 同步修正。

🤖 Generated with [Claude Code](https://github.com/claude), [CodeX](https://openai.com), [Gemini](https://github.com/apps/gemini-code-assist)
Co-Authored-By: Aurelius Huang<threefish.ai@gmail.com>
@ThreeFish-AI
ThreeFish-AI merged commit 8752caf into feature/1.x.x Jul 1, 2026
5 checks passed
@ThreeFish-AI
ThreeFish-AI deleted the ThreeFish-AI/hide-deleted-branch-commits branch July 1, 2026 14:43
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.

1 participant