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,
)
| 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"); |
nothing calls this directly
no test coverage detected