Find the repository root by searching for .atomic directory. Starts at the given path and walks up to parent directories until a `.atomic` directory is found that contains `pristine.redb` (indicating it's a repository, not just a config directory like `~/.atomic/`). The search stops at the user's home directory to prevent accidentally treating the entire home directory as a repository.
(start: &Path)
| 472 | /// The search stops at the user's home directory to prevent accidentally |
| 473 | /// treating the entire home directory as a repository. |
| 474 | pub fn find_root(start: &Path) -> Result<PathBuf, RepositoryError> { |
| 475 | let mut current = if start.is_file() { |
| 476 | start.parent().map(Path::to_path_buf) |
| 477 | } else { |
| 478 | Some(start.to_path_buf()) |
| 479 | }; |
| 480 | |
| 481 | // Get the home directory to use as a boundary |
| 482 | let home_dir = dirs::home_dir(); |
| 483 | |
| 484 | while let Some(dir) = current { |
| 485 | // Stop searching if we've reached the home directory |
| 486 | // We don't want ~/.atomic/ (config dir) to be treated as a repository |
| 487 | if let Some(ref home) = home_dir { |
| 488 | if dir == *home { |
| 489 | break; |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | let dot_dir = dir.join(DOT_DIR); |
| 494 | // Check that .atomic/ exists AND contains pristine.redb |
| 495 | // This distinguishes a repository from a config directory |
| 496 | if dot_dir.is_dir() && dot_dir.join("pristine.redb").exists() { |
| 497 | return Ok(dir); |
| 498 | } |
| 499 | current = dir.parent().map(Path::to_path_buf); |
| 500 | } |
| 501 | |
| 502 | Err(RepositoryError::NotFound { |
| 503 | path: start.display().to_string(), |
| 504 | }) |
| 505 | } |
| 506 | |
| 507 | // ── Path accessors ────────────────────────────────────────────────── |
| 508 |