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

Method find_root

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

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

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