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

Method find_root

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

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

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