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)
| 537 | /// The search stops at the user's home directory to prevent accidentally |
| 538 | /// treating the entire home directory as a repository. |
| 539 | pub fn find_root(start: &Path) -> Result<PathBuf, RepositoryError> { |
| 540 | let mut current = if start.is_file() { |
| 541 | start.parent().map(Path::to_path_buf) |
| 542 | } else { |
| 543 | Some(start.to_path_buf()) |
| 544 | }; |
| 545 | |
| 546 | // Get the home directory to use as a boundary |
| 547 | let home_dir = dirs::home_dir(); |
| 548 | |
| 549 | while let Some(dir) = current { |
| 550 | // Stop searching if we've reached the home directory |
| 551 | // We don't want ~/.atomic/ (config dir) to be treated as a repository |
| 552 | if let Some(ref home) = home_dir { |
| 553 | if dir == *home { |
| 554 | break; |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | let dot_dir = dir.join(DOT_DIR); |
| 559 | // Check that .atomic/ exists AND contains pristine.redb |
| 560 | // This distinguishes a repository from a config directory |
| 561 | if dot_dir.is_dir() && dot_dir.join("pristine.redb").exists() { |
| 562 | return Ok(dir); |
| 563 | } |
| 564 | current = dir.parent().map(Path::to_path_buf); |
| 565 | } |
| 566 | |
| 567 | Err(RepositoryError::NotFound { |
| 568 | path: start.display().to_string(), |
| 569 | }) |
| 570 | } |
| 571 | |
| 572 | // ── Path accessors ────────────────────────────────────────────────── |
| 573 |