Execute the add command. This method: 1. Finds and opens the repository 2. Collects files to add (from arguments or --all) 3. Adds each file to tracking 4. Prints the results # Errors Returns an error if: - No repository is found - A file doesn't exist - A file is inside .atomic/ - A database error occurs
(&self)
| 406 | /// - A file is inside .atomic/ |
| 407 | /// - A database error occurs |
| 408 | fn run(&self) -> CliResult<()> { |
| 409 | // Find the repository root |
| 410 | let repo_root = find_repository_root()?; |
| 411 | |
| 412 | // Open the repository |
| 413 | let repo = Repository::open(&repo_root).map_err(|e| CliError::InvalidRepository { |
| 414 | reason: e.to_string(), |
| 415 | })?; |
| 416 | |
| 417 | // Get tracking options |
| 418 | let mut options = self.get_tracking_options(); |
| 419 | if self.dry_run { |
| 420 | options.dry_run = true; |
| 421 | } |
| 422 | |
| 423 | // Collect files to add |
| 424 | let files_to_add: Vec<PathBuf> = if self.all { |
| 425 | self.collect_untracked_files(&repo)? |
| 426 | } else { |
| 427 | self.files.iter().map(PathBuf::from).collect() |
| 428 | }; |
| 429 | |
| 430 | if files_to_add.is_empty() { |
| 431 | if self.all { |
| 432 | println!("{}", info("No untracked files to add")); |
| 433 | } else { |
| 434 | return Err(CliError::InvalidArgument { |
| 435 | message: "No files specified. Use 'atomic add <files>' or 'atomic add --all'" |
| 436 | .to_string(), |
| 437 | }); |
| 438 | } |
| 439 | return Ok(()); |
| 440 | } |
| 441 | |
| 442 | // Add each file and collect stats |
| 443 | let mut total_stats = AggregateStats::new(); |
| 444 | let mut had_errors = false; |
| 445 | |
| 446 | for path in &files_to_add { |
| 447 | let path_str = path.to_string_lossy(); |
| 448 | |
| 449 | match self.add_path(&repo, &path_str, &options) { |
| 450 | Ok(stats) => { |
| 451 | // Print progress for each file |
| 452 | if self.dry_run { |
| 453 | if stats.files_added > 0 || stats.directories_added > 0 { |
| 454 | println!("Would add: {}", path_str); |
| 455 | } |
| 456 | } else if stats.files_added > 0 || stats.directories_added > 0 { |
| 457 | println!("{}: {}", added("Adding"), path_str); |
| 458 | } |
| 459 | |
| 460 | total_stats.merge(&stats); |
| 461 | } |
| 462 | Err(CliError::FileAlreadyTracked { path }) => { |
| 463 | // Not an error, just skip |
| 464 | total_stats.skipped += 1; |
| 465 | if !self.force { |