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

Method find_root

atomic-repository/src/repository/mod.rs:486–517  ·  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

484 /// The search stops at the user's home directory to prevent accidentally
485 /// treating the entire home directory as a repository.
486 pub fn find_root(start: &Path) -> Result<PathBuf, RepositoryError> {
487 let mut current = if start.is_file() {
488 start.parent().map(Path::to_path_buf)
489 } else {
490 Some(start.to_path_buf())
491 };
492
493 // Get the home directory to use as a boundary
494 let home_dir = dirs::home_dir();
495
496 while let Some(dir) = current {
497 // Stop searching if we've reached the home directory
498 // We don't want ~/.atomic/ (config dir) to be treated as a repository
499 if let Some(ref home) = home_dir {
500 if dir == *home {
501 break;
502 }
503 }
504
505 let dot_dir = dir.join(DOT_DIR);
506 // Check that .atomic/ exists AND contains pristine.redb
507 // This distinguishes a repository from a config directory
508 if dot_dir.is_dir() && dot_dir.join("pristine.redb").exists() {
509 return Ok(dir);
510 }
511 current = dir.parent().map(Path::to_path_buf);
512 }
513
514 Err(RepositoryError::NotFound {
515 path: start.display().to_string(),
516 })
517 }
518
519 // ── Path accessors ──────────────────────────────────────────────────
520

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