use std::path::PathBuf;
use crate::CoreError;
pub fn find_project_root() -> Result<PathBuf, CoreError> {
let cwd = std::env::current_dir()?;
let mut current = cwd.as_path();
loop {
if current.join(".coda").exists() || current.join(".git").exists() {
return Ok(current.to_path_buf());
}
current = current.parent().ok_or_else(|| {
CoreError::ConfigError("Not in a git repository or CODA project".into())
})?;
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_should_find_project_root_from_cwd() {
let root = find_project_root();
assert!(root.is_ok());
let root = root.unwrap();
assert!(root.join(".git").exists() || root.join(".coda").exists());
}
}