Skip to content

fix(git): 支持 Unix 冒号文件名并按字面查询历史(#2016) - #181

Merged
1lck merged 3 commits into
mainfrom
lithe-support/issue-2016-unix-colon-paths
Nov 23, 2026
Merged

1lck merged 3 commits into
mainfrom
lithe-support/issue-2016-unix-colon-paths

Conversation

@lithe-support

@lithe-support lithe-support Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

关联 Issue / Linked issue

Closes 1lck/Lithe-IDEA#2016

PR 类型 / Type

  • fix:缺陷修复

改动说明 / 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,在所有平台继续拒绝冒号与反斜杠。
  • 为普通 diff、工作区快照、未跟踪文件查询、逐行历史主查询和 merge 回放补齐 --literal-pathspecs,并为 git.write 的 commit(commits.rs 的隔离 add 与真实索引 reset)及 stashPush(write.rs)补齐 GIT_LITERAL_PATHSPECS=1。:(glob)*.txt 不再意外选中其他文件,:(exclude)*.txt 也不会把所选文件排除。
  • 增加 9 个真实临时 Git 仓库的 Core JSON 回归(含接管审查新增的 selected_commit_keeps_colon_paths_literal 与 stash_push_keeps_colon_paths_literal),以及 3 个跨平台/规则边界测试;同步更新旧的目录汇总回归。临时仓库由 fixture 负责清理,所有 Git 请求都有 5 秒截止时间。

不在本 PR 范围内 / Out of scope

宿主固定 Core 版本的升级及原生应用验收不在此 Core PR 中;请求、响应和插件协议版本没有变化。

类型专属:fix

复现与根因

  1. 基础回归在 Unix 临时仓库创建 a:b.txt、:(glob)*.txt、D:\logs 与 :(exclude)*.txt。
  2. 接管审查时追加审计 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。
  3. 补齐 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 通过。
  • [N/A] 手动替代步骤:已有真实 Git 仓库自动化复现。
  • 搜索并审查 is_safe_pathspec、validate_paths、--pathspec-from-file 与 -- 的全部调用方(含 commit_selected_paths 与 stashPush)。
  • 另一平台的规则使用 Platform 参数化路径实现并在 lithe-platform 与 lithe-git 对两平台各测一次,没有在 Git crate 新增操作系统特判。
  • 修改限定在校验边界、受影响的 Git 参数和回归测试。

范围检查 / Scope checks

  • 功能矩阵: N/A(Core 仓库既有 Git 行为修复,无宿主实现或矩阵修改)。
  • 插件归属: 全部新增输入为测试自建临时 Git 仓库和文件,无具体插件依赖。
  • UI / 界面文案 / 设置 / 插件契约 / 发行包: N/A。
  • 统一日志系统: 无新增或修改日志事件,generate-log-events.mjs --check 通过。
  • 逻辑归属: 路径规则归 lithe-platform,引用校验与 Git 参数编排归 lithe-git,Core 仅保留 JSON 边界集成回归。
  • 无用代码与重构: 已替换不再适用的引用名路径校验及对应 import;没有附带重构。

验证 / Verification

命令或操作 平台 结果
修复前 selected_commit / stash_push 回归 macOS arm64 / Rust 1.100.0 2/2 预期失败(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-platform macOS arm64 / Rust 1.100.0 (合入 9c8e89a 后,HEAD 57a4ad8) 1425/1425 通过,0 失败 / 0 忽略:Core 922 单元 + 35 集成 = 957(含 git_colon_paths 9/9)、Git 161(含 Platform 规则单测)、LSP-engine 179、Platform 26、Project 102
cargo 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 warnings macOS arm64 / Rust 1.100.0 通过
LIBSQLITE3_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 macOS 交叉检查 / Rust 1.100.0 通过(仅编译检查,不代替原生 Windows 运行)
./scripts/rust-core/verify-rust-core-comments.sh core git lsp-engine project macOS arm64 / Rust 1.100.0 通过
cargo fmt --manifest-path rust/Cargo.toml --all -- --check & git diff --check origin/main HEAD macOS arm64 / Rust 1.100.0 通过
node scripts/rust-core/verify-platform-tests.mjs macOS arm64 52 crates 放置检查通过
node --test scripts/rust-core/*.test.mjs macOS arm64 16/16 通过
node scripts/logging/generate-log-events.mjs --check macOS arm64 149 个日志事件目录通过
./.agents/skills/write-stable-tests/scripts/verify-test-stability.sh --base origin/main macOS arm64 0 violations

未能执行的检查和原因: 原生 Windows 测试未在本地执行(仅运行 x86_64-pc-windows-msvc clippy 静态检查;Platform::Windows 规则已在 lithe-platform 与 lithe-git 单测覆盖)。

提交前确认 / Final checks

  • 分支已合入最新 origin/main (9c8e89a, HEAD 57a4ad8),全部最终验证在该提交上通过。
  • Draft PR(待维护者标记 ready),不自动合并。
  • 不提交 target、.artifacts、临时仓库、日志或凭据;测试夹具已清理。

@1lck
1lck marked this pull request as ready for review November 23, 2026 13:15
@1lck
1lck merged commit 04fc99c into main Nov 23, 2026
11 of 14 checks passed
@1lck
1lck deleted the lithe-support/issue-2016-unix-colon-paths branch November 23, 2026 13:23
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.

[Bug] macOS 上 Git 操作拒绝文件名含 ":" 的文件:is_safe_pathspec 同时校验 ref 和工作区路径

1 participant