Repository navigation
feat(git): 多仓库共同分支 git.workspaceCommonReferences;图投影 checkedOutHeads 按各仓库检出分支标记当前分支 - #75
Merged
Merged
Conversation
…按各仓库检出分支标记当前分支 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…an 多仓库检出/新建分支计划与回滚 - git.workspaceCommonReferences 输入改为各仓库 git.references 的 references 原样传回,响应用同一条目形状,ahead/behind 按仓库相加,不列标签 - 新增 git.workspaceBranchPlan:按 IDEA GitBranchOperation 规划检出、新建分支在各仓库的步骤、跳过已在该分支的仓库,并给出每步回滚动作 - graphProjection 复用 HEAD -> 解析;currentBranch 与 checkedOutHeads 同时出现时返回 invalid_request - 补齐无效测试用例(NUL、超长名、命名空间不符、重复、上游无效、多个当前分支等)和上限单测,增加真实 Git 直通测试
27 of 33 tasks
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.
关联 Issue / Linked issue
5c48a67,本 PR 合入后换成 main 上的 commit)PR 类型 / Type
改动说明 / What changes
背景 / Why
#2013 要多仓库文件夹的 Git 用法和 IntelliJ IDEA 一致。对照 IDEA 打开多根项目的界面,还差三处需要 Core 决定的规则:
GitRefUtil.findCommon、GitMultiRootBranchConfig.getTrackedBranch)。“哪些分支算共同、上游显示哪个、哪个算当前、领先/落后怎么算”是通用规则。GitBranchOperation)。执行顺序、跳过哪些仓库、每一步怎么撤销也是通用规则。git.graphProjection的currentBranch只接受一个分支名,从第一个带该名字的提交开始走祖先。混排日志里各仓库检出的分支不同(例如 frontend 在 develop,backend 在 main),结果只有排在最前的那个仓库被高亮。IDEA 的CurrentBranchHighlighter按每个提交所在根的当前分支判断。改动 / Changes
新命令
git.workspaceCommonReferences(rust/crates/git/src/workspace_repositories/common_references.rs){ repositories: [{ id, references }] }。references是该仓库git.references响应里的references列表,原样传入,宿主不用另做转换。Core 读取fullName、shortName、kind、isCurrent、upstreamShortName、ahead、behind,其余字段忽略。{ local, remote },元素就是git.references的条目,宿主可以用画单仓库分支行的同一套代码画出来。fullName匹配所有仓库都有的本地、远程分支,按第一个仓库的顺序;不列标签。isCurrent: true。upstreamShortName只在每个仓库都跟踪同一个远程分支时给出,否则为null(IDEA 的getTrackedBranch)。ahead/behind是各仓库相对自己上游的数量之和,任一仓库有待推送或待拉取的提交,共同分支就有标记(与 IDEA 一致)。invalid_request:ID 无效或重复、缺少references、未知kind、名称为空 / 含 NUL / 超过 4096 字节、fullName与shortName和类型对不上、同一仓库内fullName重复、upstreamShortName为空或含 NUL、一个仓库有多个当前引用或当前引用不是本地分支、条目之外的未知字段。新命令
git.workspaceBranchPlan(rust/crates/git/src/workspace_repositories/branch_plan.rs){ operation: "checkout" | "createBranch", reference, name?, checkout?, repositories },repositories与上一个命令相同,顺序就是执行顺序。{ steps: [{ repository, reference, rollback }], skipped }。reference是该仓库里这个共同分支的{ fullName, shortName, kind },直接作为该步git.write(checkout,或带name、checkout的createBranch)的gitReference。rollback:[{ operation: "checkout" | "deleteBranch", reference }]。skipped,不生成步骤;撤销检出就是切回原来的本地分支。撤销远程分支的检出时,保留检出时新建或移动的本地分支,因为计划不读取远程。checkout为真时先切回原分支,再删除新分支。rollback为null,没有办法切回去。invalid_request:沿用上一个命令对repositories的检查;另外,以下情况也会返回:reference在某个仓库不存在,或者是标签;createBranch缺少合法的name,或者某个仓库已有refs/heads/<name>;checkout带了name或checkout: true;operation,或者条目之外的未知字段。git.graphProjection新增checkedOutHeads(rust/crates/git/src/graph.rs)false,现有调用不变。true时,currentBranchHashes从每个带HEAD -> <name>装饰的提交(即每个仓库检出的分支)开始走祖先;分离的HEAD不作为起点。currentBranch同时发送时返回invalid_request。current_branch_hashes的遍历抽成ancestry,单分支行为不变。契约和 fixture
rust/contracts/rust-core-api.md:命令表两行,以及三段说明。rust/fixtures/git/workspace-common-references-v1.json(6 个正常用例、18 个非法用例)、workspace-branch-plan-v1.json(5 个正常用例、14 个非法用例);graph-projection-v1.json新增非法用例currentBranchWithCheckedOutHeads。lithe-git 单测和 lithe-core 分发测试都读这些 fixture。references_pass_through_to_common_branches_and_the_branch_plan:在真实仓库上把git.references的响应原样交给两个新命令,按计划执行git.write后再按rollback撤销。共 14 个文件,+1511 / −19。
验证
本分支已合并 Core main
6f5fbcc(#87,含 #90、#89、#88)。cargo fmt --all -- --check、cargo clippy -p lithe-git -p lithe-core --all-targets --all-features -- -D warnings:通过。cargo test -p lithe-git --lib:157 passed。cargo test -p lithe-core:820 passed(含两个新命令的 fixture 分发测试和真实仓库测试)。5c48a67:Go 全量测试 59 个包通过;无头截图里能看到共同本地分支、部分完成时的回滚对话框和混排日志里两个仓库的当前分支高亮。不在本 PR 范围内