Skip to content

Commit 6a3a617

Browse files
committed
feat(execution): 构建检测和运行项发现跳过被 Git 忽略的目录
build.detect 和自动运行项发现共用的启发式扫描(最多 6 层)现在会按 Git 的忽略规则剪掉目录:.claude/worktrees 下的代理工作树、生成目录和本地副本 不再被当成候选根目录,构建窗口不会把每个模块列两遍。 - 规则来自工作区内途经的 .gitignore,以及根目录在工作区内的仓库的 info/exclude;gitfile 按 gitdir: 解析,链接工作树经 commondir 读主仓库 共享的 info/exclude;嵌套仓库另起一套规则;深层文件先匹配先决定, 支持 ! 重新包含。 - 不读工作区根以上的目录、core.excludesFile 和索引;读不到的忽略文件不加 规则(只会多看到目录),远程连接中断仍然让扫描失败。 - 指纹扫描和 Node 清单发现(不限深度的完整扫描)不变,仍遍历被忽略的目录。 - 契约 README、构建系统参考页、rust-core-api.md 写明检测深度和忽略规则; 协议更新记录加一行。
1 parent df95582 commit 6a3a617

9 files changed

Lines changed: 390 additions & 15 deletions

File tree

‎rust/Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎rust/contracts/rust-core-api.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3210,7 +3210,13 @@ revision and the diagnostic says so instead of listing modified files.
32103210
Automatic run discovery, fingerprint traversal and Node manifest discovery use
32113211
Core's shared scan policy. Known caches/build outputs
32123212
are pruned before descending; other hidden source directories remain visible and
3213-
symlinks are not followed. Failure to read the workspace root is an error. An
3213+
symlinks are not followed. Automatic run discovery and `build.detect` search at
3214+
most 6 levels and also prune directories Git ignores, using the `.gitignore`
3215+
files they pass and the `info/exclude` of each repository whose root lies in the
3216+
workspace (a linked worktree reads the main repository's shared one); a nested
3217+
repository starts its own rules. Nothing above the workspace root is read, nor
3218+
`core.excludesFile` or the index. Fingerprint traversal and Node manifest
3219+
discovery keep ignored directories. Failure to read the workspace root is an error. An
32143220
unreadable optional child or fingerprint input is recorded in
32153221
`generator.unreadablePaths`; generation retains previous configurations and input
32163222
hashes beneath those unknown paths. Inspection returns `incompleteProjectScan`

‎rust/crates/core/src/tests/build_systems.rs‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,29 @@ fn detection_applies_nesting_priority_and_rejections() {
754754
assert_eq!(gradle["markers"], json!(["android/settings.gradle.kts"]));
755755
}
756756

757+
/// A directory Git ignores is no candidate root: agent worktrees and local copies
758+
/// repeat the project's own manifests, and would list every module twice.
759+
#[test]
760+
fn detection_skips_directories_git_ignores() {
761+
let package = |name: &str| format!("[package]\nname = \"{name}\"\nversion = \"0.1.0\"\n");
762+
let workspace = TemporaryWorkspace::new("build-detect-ignored");
763+
workspace
764+
.write(".git/HEAD", "ref: refs/heads/main\n")
765+
.write(".git/info/exclude", ".claude/worktrees/\n")
766+
.write(".gitignore", "/scratch/\n")
767+
.write("Cargo.toml", &package("app"))
768+
.write("tools/Cargo.toml", &package("tools"))
769+
.write("scratch/Cargo.toml", &package("scratch"))
770+
.write(".claude/worktrees/copy/Cargo.toml", &package("app"));
771+
772+
let detection = detect(
773+
&workspace,
774+
vec![fixture("build-static-file.plugin.json")],
775+
json!({}),
776+
);
777+
assert_eq!(instance_ids(&detection), ["cargo:.", "cargo:tools"]);
778+
}
779+
757780
#[test]
758781
fn detection_returns_empty_for_non_directory_and_missing_workspace_roots() {
759782
let workspace = TemporaryWorkspace::new("build-detect-non-directory");

‎rust/crates/core/src/tests/remote_sessions.rs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,10 @@ fn shared_run_scan_reads_the_host_tree_and_stops_when_the_link_drops() {
747747
std::fs::create_dir_all(remote.join("service/api")).unwrap();
748748
std::fs::write(remote.join("package.json"), "{}").unwrap();
749749
std::fs::write(remote.join("service/tool-a.toml"), "").unwrap();
750+
// The ignore rules are the host's: the placeholder has no `.gitignore`.
751+
std::fs::create_dir_all(remote.join("generated")).unwrap();
752+
std::fs::write(remote.join("generated/package.json"), "{}").unwrap();
753+
std::fs::write(remote.join(".gitignore"), "generated/\n").unwrap();
750754
let workspace = serde_json::from_value(
751755
json!({"sessionId": host.id, "localRoot": local, "remoteRoot": remote}),
752756
)
@@ -768,7 +772,10 @@ fn shared_run_scan_reads_the_host_tree_and_stops_when_the_link_drops() {
768772
assert_eq!(
769773
files,
770774
[
771-
(std::path::PathBuf::new(), vec!["package.json".to_owned()]),
775+
(
776+
std::path::PathBuf::new(),
777+
vec![".gitignore".to_owned(), "package.json".to_owned()]
778+
),
772779
("service".into(), vec!["tool-a.toml".to_owned()]),
773780
("service/api".into(), Vec::new()),
774781
]

‎rust/crates/execution/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ description = "Run configurations for Lithe: generation, resolution, launch envi
1010
test-support = []
1111

1212
[dependencies]
13+
ignore = "=0.4.33"
1314
lithe-diagnostics = { path = "../diagnostics" }
1415
lithe-plugin-model = { path = "../plugin-model" }
1516
lithe-protocol = { path = "../protocol" }

0 commit comments

Comments
 (0)