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

Method find_root

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

500 /// The search stops at the user's home directory to prevent accidentally
501 /// treating the entire home directory as a repository.
502 pub fn find_root(start: &Path) -> Result<PathBuf, RepositoryError> {
503 let mut current = if start.is_file() {
504 start.parent().map(Path::to_path_buf)
505 } else {
506 Some(start.to_path_buf())
507 };
508
509 // Get the home directory to use as a boundary
510 let home_dir = dirs::home_dir();
511
512 while let Some(dir) = current {
513 // Stop searching if we've reached the home directory
514 // We don't want ~/.atomic/ (config dir) to be treated as a repository
515 if let Some(ref home) = home_dir {
516 if dir == *home {
517 break;
518 }
519 }
520
521 let dot_dir = dir.join(DOT_DIR);
522 // Check that .atomic/ exists AND contains pristine.redb
523 // This distinguishes a repository from a config directory
524 if dot_dir.is_dir() && dot_dir.join("pristine.redb").exists() {
525 return Ok(dir);
526 }
527 current = dir.parent().map(Path::to_path_buf);
528 }
529
530 Err(RepositoryError::NotFound {
531 path: start.display().to_string(),
532 })
533 }
534
535 // ── Path accessors ──────────────────────────────────────────────────
536

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