Repository navigation
fix(git): 支持 Unix 冒号文件名并按字面查询历史(#2016) - #181
Merged
Merged
Conversation
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
Closes 1lck/Lithe-IDEA#2016
PR 类型 / Type
改动说明 / What changes
背景 / Why
Unix 工作区中的
a:b.txt、D:\logs等合法文件名可以被 Git 跟踪,但 Core 的路径校验提前返回invalid_request,导致暂存、忽略、差异查看和历史查询失败。改动 / Changes
lithe_platform::paths::invalid_native_relative_path:Unix 保留冒号和反斜杠的文件名语义;Windows 继续拒绝盘符和 alternate data stream 形式,绝对路径、目录穿越和 NUL 仍被拒绝。lithe-git拆出is_safe_pathspec_for(path, platform)并新增无cfg的Platform::Unix/Platform::Windows规则单测;将分支名、远端名和 refspec 组成部分校验拆为is_safe_refspec_name,在所有平台继续拒绝冒号与反斜杠。--literal-pathspecs,并为git.write的commit(commits.rs的隔离add与真实索引reset)及stashPush(write.rs)补齐GIT_LITERAL_PATHSPECS=1。:(glob)*.txt不再意外选中其他文件,:(exclude)*.txt也不会把所选文件排除。selected_commit_keeps_colon_paths_literal与stash_push_keeps_colon_paths_literal),以及 3 个跨平台/规则边界测试;同步更新旧的目录汇总回归。临时仓库由 fixture 负责清理,所有 Git 请求都有 5 秒截止时间。不在本 PR 范围内 / Out of scope
宿主固定 Core 版本的升级及原生应用验收不在此 Core PR 中;请求、响应和插件协议版本没有变化。
类型专属:fix
复现与根因
a:b.txt、:(glob)*.txt、D:\logs与:(exclude)*.txt。write.rs与commits.rs全部validate_paths/--pathspec-from-file调用方,发现commit(commit_selected_paths)与stashPush仍未启用字面 pathspec:修复前新增回归selected_commit_keeps_colon_paths_literal仅提交了D:\logs(diff-tree实测:(exclude)*.txt排除了其余*.txt与a:b.txt),stash_push_keeps_colon_paths_literal未暂存a:b.txt。GIT_LITERAL_PATHSPECS=1后,9/9 真实仓库回归全部通过,且确认unselected.txt未被意外提交、暂存或 stash。根因是
repository::is_safe_pathspec对所有平台执行!normalized.contains(':'),同时又被 3 个引用名校验位置复用;且开放冒号路径后,所有接收工作区路径作为 pathspec 的 Git 命令必须保持字面模式。检查项
rust/crates/core/src/tests/git_colon_paths.rs,初始 6/6 返回invalid_request;补充 merge 回归实际返回空历史;接管审查新增selected_commit_keeps_colon_paths_literal与stash_push_keeps_colon_paths_literal在修复前实测失败;最终 9/9 通过。is_safe_pathspec、validate_paths、--pathspec-from-file与--的全部调用方(含commit_selected_paths与stashPush)。Platform参数化路径实现并在lithe-platform与lithe-git对两平台各测一次,没有在 Git crate 新增操作系统特判。范围检查 / Scope checks
generate-log-events.mjs --check通过。lithe-platform,引用校验与 Git 参数编排归lithe-git,Core 仅保留 JSON 边界集成回归。验证 / Verification
selected_commit/stash_push回归commit只提交D:\logs;stashPush漏掉a:b.txt)env -u GIT_EDITOR cargo test --locked --manifest-path rust/Cargo.toml -p lithe-core -p lithe-git -p lithe-lsp-engine -p lithe-project -p lithe-platform9c8e89a后,HEAD57a4ad8)git_colon_paths9/9)、Git 161(含Platform规则单测)、LSP-engine 179、Platform 26、Project 102cargo clippy --locked --manifest-path rust/Cargo.toml -p lithe-core -p lithe-git -p lithe-lsp-engine -p lithe-project --all-targets --all-features -- -D warningsLIBSQLITE3_SYS_USE_PKG_CONFIG=1 cargo clippy --locked --manifest-path rust/Cargo.toml -p lithe-core -p lithe-git -p lithe-lsp-engine -p lithe-project --all-targets --target x86_64-pc-windows-msvc -- -D warnings./scripts/rust-core/verify-rust-core-comments.sh core git lsp-engine projectcargo fmt --manifest-path rust/Cargo.toml --all -- --check&git diff --check origin/main HEADnode scripts/rust-core/verify-platform-tests.mjsnode --test scripts/rust-core/*.test.mjsnode scripts/logging/generate-log-events.mjs --check./.agents/skills/write-stable-tests/scripts/verify-test-stability.sh --base origin/main未能执行的检查和原因: 原生 Windows 测试未在本地执行(仅运行
x86_64-pc-windows-msvcclippy 静态检查;Platform::Windows规则已在lithe-platform与lithe-git单测覆盖)。提交前确认 / Final checks
origin/main(9c8e89a, HEAD57a4ad8),全部最终验证在该提交上通过。