Repository navigation
feat(git): 多仓库工作区的仓库身份、当前仓库选择与改动分组移入 Core - #65
Merged
Merged
Conversation
…ps in Core A folder without its own .git that holds several independent repositories is opened as one project (1lck/Lithe-IDEA#2013). The desktop decided in Go which repository a view acts on, how the repositories' changes group and stage, and whether a parent still has to record a nested commit, and it assumed the opened folder is always a repository. Core now owns those rules so every host shares them. - workspace.repositories entries carry id (relative to the opened folder, `/`-separated, `..` for an enclosing repository), name and role (workspace or nested). A folder outside every repository has no workspace entry. Remote workspaces compute IDs from host paths. - git.workspaceRepositorySelection takes the discovery entries and the previous pick, and answers the repository to act on, whether it fell back, and the others in discovery order. - git.workspaceChangeGroups takes the discovery entries with their git.status changes, and answers per-repository groups, counts, the checkbox states, the paths each checkbox stages or unstages, and whether the deepest listed ancestor's gitlink to a nested repository moved. An untracked or ignored independent repository gets no parent hint. - git.workspaceCommitPrepare accepts workspaceRepositories and binds every nested repository the host did not bind, except for path-scoped commits and retries, so the reviewed plan never gains repositories between attempts. Fixtures: rust/fixtures/git/workspace-repository-selection-v1.json, rust/fixtures/git/workspace-change-groups-v1.json, and the extended rust/fixtures/workspace/repositories-v1.json. Refs 1lck/Lithe-IDEA#2013
xiaoyumuxi
marked this pull request as ready for review
November 16, 2026 09:23
This was referenced Nov 16, 2026
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
PR 类型 / Type
改动说明 / What changes
背景 / Why
#2013 的场景:打开一个本身没有
.git的父文件夹,里面有几个独立仓库。现在桌面端(Viva,Go)自己在 Go 里判断:而且它默认打开的文件夹本身一定是仓库。按“通用逻辑进 Rust Core”的规则,这些规则先迁入 Core,并补齐契约和 fixture。下一步桌面端只负责呈现和执行原生 Git 写入。
迁移时顺带修正了 Go 里
submoduleReferenceChanged的一个缺陷:Core 改为按主机路径找到列表中最近的祖先仓库,再用相对该祖先的路径去匹配祖先的 gitlink 改动。
改动 / Changes
workspace.repositories条目新增id、name、role(rust/crates/git/src/contracts.rs、repository.rs)id:相对打开文件夹、用/分隔的身份:.;service-a、libs/core;..(打开的是某个检出的packages/app时为../..)。role:workspace:包含打开文件夹的仓库,即文件夹自身或外层检出。最多一个,总是排第一。nested:文件夹下面的仓库。workspace条目。name:视图显示的标签。workspace 仓库显示根目录名,nested 仓库显示id,这样同名的两个嵌套目录也能区分。新命令
git.workspaceRepositorySelection(rust/crates/git/src/workspace_repositories/selection.rs){ repositories: <workspace.repositories 条目原样>, selected? }。{ active, fellBack, others }。active的取值顺序:workspace条目;null。selected且它已不在列表里时,fellBack才为true。others按发现顺序列出其余 ID。branchRoot默认值、branchGroups、referenceGroups和logFallsBack。新命令
git.workspaceChangeGroups(rust/crates/git/src/workspace_repositories/change_groups.rs){ repositories: [<workspace.repositories 条目> + changes: <该仓库 git.status 的 changes 原样>] }。fileCount、stagedCount、allStaged、toggleable;staging: { operation, paths };parentReference(moved或unchanged)。fileCount、stagedCount、allStaged,以及总复选框的stageAll: { operation, repositories: [{ id, paths }] }。parentReference:commitChanged;nested_repos_view.go的分组与allStaged,以及stageAllRepositories、submoduleReferenceChanged。两条新命令共用的校验(
rust/crates/git/src/workspace_repositories.rs)拒绝发现结果不可能产生的列表,返回
invalid_request:/开头,或含\或 NUL;name为空;workspace条目;git.workspaceCommitPrepare新增可选workspaceRepositories(rust/crates/git/src/workspace_commit.rs)workspace.repositories条目原样,按上面的规则校验。id,绑定宿主没有绑定的每个nested仓库。workspace条目始终由宿主自己绑定,Core 不会添加。pathScope,或previous计划带pathScope时,不添加任何仓库。previous会话里已有的 ID,所以经过确认的计划不会在两次尝试之间多出仓库。includeNestedRepositories。协议接线与文档
rust/crates/core/src/protocol/command.rs、runtime/dispatcher/git.rs:注册两条新命令。rust/contracts/rust-core-api.md:命令表新增两行,并更新以下几处说明:workspace.repositories的id/role/name;git.workspaceCommitPrepare的workspaceRepositories。Fixture 与测试
rust/fixtures/git/workspace-repository-selection-v1.json:6 个正常用例、9 个非法用例;rust/fixtures/git/workspace-change-groups-v1.json:6 个正常用例、8 个非法用例。rust/fixtures/workspace/repositories-v1.json,覆盖以下情况:lithe-git单元测试覆盖以下内容:lithe-core新增tests/git_workspace_repositories.rs:execute_json跑两份 fixture;libs/B、被.gitignore忽略的独立仓库extras。验证 discovery 和 status 原样传入后的选择、分组、stageAll,以及子仓库提交前后parentReference从unchanged变为moved。tests/git_workspace_commit.rs新增真实 Git 测试,覆盖:pathScope时不添加;invalid_request。tests/git.rs、git_repository_discovery.rs、remote_sessions.rs:按新的条目形状更新断言。不在本 PR 范围内 / Out of scope
PINNED_CORE_REVISION,全部改用 Core 的 ID;parentReference == "unchanged"时显示;类型专属:feat
多平台对齐
范围检查 / Scope checks
git-multi-repository-references随桌面端接入 PR 一起更新。name是文件名,不翻译。workspaceCommitPrepare只对发现的嵌套仓库多做一次validate_root。验证 / Verification
本机为 Apple M4,Rust 1.100.0。
cargo fmt --manifest-path rust/Cargo.toml --all -- --checkscripts/rust-core/verify-rust-core-comments.shnode scripts/rust-core/verify-platform-tests.mjsnode --test scripts/rust-core/*.test.mjsnode scripts/rust-core/affected-crates.mjs--workspace;macOS、Windows 只跑平台测试 cratecargo test --manifest-path rust/Cargo.toml --workspace --features lithe-remote/server --no-fail-fastcargo clippy --manifest-path rust/Cargo.toml --workspace --all-targets -- -D warningscargo clippy --manifest-path rust/Cargo.toml --workspace --all-targets --target x86_64-pc-windows-msvc -- -D warningswrite-stable-tests的verify-test-stability.mjs,以本仓库为根未能执行的检查和原因:
affected-crates,PR CI 只在 Linux 上跑lithe-git、lithe-core的测试,Windows 只编译检查。路径规则在 Windows 上的表现,等桌面端接入后在 Windows 虚拟机上验收。提交前确认 / Final checks
main(ad148ec)创建,目标分支main。