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

Method add_directory

atomic-repository/src/repository/tracking.rs:451–522  ·  view source on GitHub ↗

Add an empty directory to tracking explicitly. Unlike `add()` which only tracks files (directories are created implicitly), this method explicitly tracks empty directories as first-class citizens in the repository graph. This is useful for: - Preserving empty directory structure (no `.keep` files needed) - Tracking directories that will be populated later - Ensuring directory creation during clo

(
        &self,
        working_copy: WorkingCopyId,
        path: P,
        options: TrackingOptions,
    )

Source from the content-addressed store, hash-verified

449 /// └────────────────────────────────────────────────────────────────┘
450 /// ```
451 pub fn add_directory<P: AsRef<Path>>(
452 &self,
453 working_copy: WorkingCopyId,
454 path: P,
455 options: TrackingOptions,
456 ) -> Result<TrackingStats, RepositoryError> {
457 use crate::tracking::add_directory_to_tree;
458
459 self.validate_working_copy(working_copy)?;
460 let path = path.as_ref();
461 let mut stats = TrackingStats::new();
462
463 // Load ignore rules
464 let rules = self.load_ignore_rules();
465
466 // Check for internal paths and ignore patterns
467 // For add_directory, we know the path is a directory
468 if should_ignore_with_rules(path, true, true, Some(&rules)) {
469 return Err(RepositoryError::PathOutsideRepository {
470 path: path.to_path_buf(),
471 });
472 }
473
474 // Verify the path exists and is a directory
475 let abs_path = self.root.join(path);
476 if !abs_path.exists() {
477 return Err(RepositoryError::FileNotFound {
478 path: path.to_path_buf(),
479 });
480 }
481
482 if !abs_path.is_dir() {
483 return Err(RepositoryError::InvalidOperation {
484 message: format!("Path is not a directory: {}", path.display()),
485 });
486 }
487
488 let normalized = normalize_path(path);
489
490 // Don't modify if dry run
491 if options.dry_run {
492 stats.explicit_directories_added += 1;
493 return Ok(stats);
494 }
495
496 let mut txn = self
497 .pristine
498 .write_txn()
499 .map_err(|e| RepositoryError::Database(e.to_string()))?;
500
501 // Check if already tracked
502 if is_tracked(&txn, &normalized).map_err(|e| RepositoryError::Database(e.to_string()))? {
503 if !options.force {
504 return Err(RepositoryError::FileAlreadyTracked {
505 path: path.to_path_buf(),
506 });
507 }
508 stats.skip(path.to_path_buf(), "already tracked");

Callers

nothing calls this directly

Calls 12

should_ignore_with_rulesFunction · 0.85
is_trackedFunction · 0.85
add_directory_to_treeFunction · 0.85
validate_working_copyMethod · 0.80
as_refMethod · 0.80
load_ignore_rulesMethod · 0.80
is_dirMethod · 0.80
write_txnMethod · 0.80
skipMethod · 0.80
normalize_pathFunction · 0.50
existsMethod · 0.45
commitMethod · 0.45

Tested by

no test coverage detected