MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / find_root

Method find_root

atomic-repository/src/repository/mod.rs:584–615  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

582 /// The search stops at the user's home directory to prevent accidentally
583 /// treating the entire home directory as a repository.
584 pub fn find_root(start: &Path) -> Result<PathBuf, RepositoryError> {
585 let mut current = if start.is_file() {
586 start.parent().map(Path::to_path_buf)
587 } else {
588 Some(start.to_path_buf())
589 };
590
591 // Get the home directory to use as a boundary
592 let home_dir = dirs::home_dir();
593
594 while let Some(dir) = current {
595 // Stop searching if we've reached the home directory
596 // We don't want ~/.atomic/ (config dir) to be treated as a repository
597 if let Some(ref home) = home_dir {
598 if dir == *home {
599 break;
600 }
601 }
602
603 let dot_dir = dir.join(DOT_DIR);
604 // Check that .atomic/ exists AND contains pristine.redb
605 // This distinguishes a repository from a config directory
606 if dot_dir.is_dir() && dot_dir.join("pristine.redb").exists() {
607 return Ok(dir);
608 }
609 current = dir.parent().map(Path::to_path_buf);
610 }
611
612 Err(RepositoryError::NotFound {
613 path: start.display().to_string(),
614 })
615 }
616
617 // ── Path accessors ──────────────────────────────────────────────────
618

Callers

nothing calls this directly

Calls 5

parentMethod · 0.80
is_dirMethod · 0.80
displayMethod · 0.80
is_fileMethod · 0.45
existsMethod · 0.45

Tested by

no test coverage detected