Files
fermata/src/core/project.rs
T
g4borg fd2482e3e6 fix(fermata): .botignore no longer stops project-root walk-up
Only .git, botignore.toml, and .botignore.toml define project boundaries.
A bare .botignore is a policy file, not a root marker.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-08 23:30:30 +02:00

28 lines
876 B
Rust

use std::path::{Path, PathBuf};
/// Markers checked in priority order when walking up from a target path.
const MARKERS: &[&str] = &["botignore.toml", ".botignore.toml", ".git"];
/// Walk upward from `target` (or its parent if `target` is a file) looking
/// for the nearest project root. Roots are identified by the presence of
/// any marker in `MARKERS`. Walks from the **target file's location**, not
/// from cwd, because agents `cd` around.
pub fn find_project_root(target: &Path) -> Option<PathBuf> {
let start = if target.is_file() {
target.parent()?
} else {
target
};
let mut current = Some(start);
while let Some(dir) = current {
for marker in MARKERS {
if dir.join(marker).exists() {
return Some(dir.to_path_buf());
}
}
current = dir.parent();
}
None
}