feat(Branches): 远程分支支持右键删除(git push --delete)#42
Merged
Conversation
- 新增 hyperGit.deleteRemoteBranch 命令,挂载到远程分支右键菜单(与本地「删除分支」同槽位 1_branch@2,视觉对称),commandPalette 以 when:false 隐藏
- 经 git push <remote> --delete <branch> 删除服务端分支,并对成功项执行 branch -D -r 即时清理本地 remote-tracking ref,使视图立即同步
- 新增纯逻辑 src/engine/ref/remote-ref.ts:
· resolveRemoteBranch 用已知 remotes 做最长前缀匹配拆分 {remote, branch},remote 名含斜杠(如 myorg/repo)亦安全,禁用朴素 split('/')[0]
· partitionRemoteByProtected 复用 isProtectedBranch(SSOT),硬阻断 origin/main、origin/master
· formatRemoteDeleteConfirm 诚实传达「服务器端不可逆 + 影响协作者」,支持单/多选与当前分支上游软警示
- 复用 selectedBranchRefs(多选归一化)/ execGit / 统一 modal 确认范式,零重定义;不调用 handleGitConflict(删除不产生合并冲突)
- 新增 tests/unit/ref-remote.test.ts(16 个用例,覆盖斜杠安全/歧义/受保护分桶/确认文案)
🤖 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>
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.
背景
Branches 视图中,远程分支(
origin/foo)的右键菜单缺少删除操作——本地分支有「删除分支」(git branch -d/-D),远程分支无对应入口。远程分支删除是与之正交的另一机制:git push <remote> --delete <branch>,作用于服务器、影响协作者、不可撤销。本 PR 补齐该能力。改动概要
新增独立命令
hyperGit.deleteRemoteBranch,挂载到远程分支右键菜单(与本地「删除分支」同槽位1_branch@2,视觉对称),经git push <remote> --delete <branch>删除服务端分支。文件清单
src/engine/ref/remote-ref.tssrc/adapter/remote-commands.tshyperGit.deleteRemoteBranchhandlerpackage.jsoncommands/view/item/context/commandPalette各 +1 条tests/unit/ref-remote.test.ts核心设计
resolveRemoteBranch用「已知 remotes 列表」做最长前缀匹配拆分{remote, branch},正确处理 remote 名含斜杠(如 fork 场景myorg/repo);禁用朴素split('/')[0](会把myorg/repo/feature错切成myorg,推到不存在的 remote 甚至误删)。origin/main/origin/master一律跳过并告知,复用isProtectedBranch(SSOT),与本地删除硬阻断当前 HEAD 对称。git branch -D -r清理本地 remote-tracking ref,分支在视图立即消失(清理失败非关键,下次fetch --prune自然收敛)。selectedBranchRefs(多选归一化)/execGit/ 统一 modal 确认范式 /truncateNames,零重定义;支持多选批量删除、失败汇总。不调用handleGitConflict(删除不产生合并冲突)。边缘场景
origin/main/origin/mastermyorg/repo)push --delete非零退出 → 计入 failures(与本地branchDelete一致)(r) => r.isRemote && !r.isTag自动过滤验证
pnpm check-types(tsc --noEmit,0 error)pnpm lint(eslint 全量,0 error)pnpm test:unit(vitest,30 文件 / 296 用例全绿,含新增 16 个)node esbuild.js(打包通过)origin/main自动跳过受保护;命令面板搜不到(when:false)。(待人工核验)兼容性
branchDelete/tagDelete/pushDialog等行为;本地分支、标签删除流程不受影响。🤖 Generated with Claude Code