Execute the remove command. # Process 1. Find and open the repository 2. For each path: a. Remove from tracking b. If not --keep, delete from disk 3. Display results
(&self)
| 232 | /// b. If not --keep, delete from disk |
| 233 | /// 3. Display results |
| 234 | fn run(&self) -> CliResult<()> { |
| 235 | // Find repository |
| 236 | let repo_root = find_repository_root()?; |
| 237 | let repo = Repository::open(&repo_root).map_err(CliError::Repository)?; |
| 238 | |
| 239 | let options = self.to_tracking_options(); |
| 240 | let action = self.format_action(); |
| 241 | |
| 242 | let mut total_removed = 0; |
| 243 | let mut total_errors = 0; |
| 244 | let mut files_to_delete: Vec<PathBuf> = Vec::new(); |
| 245 | |
| 246 | // Process each path |
| 247 | for path in &self.paths { |
| 248 | // Normalize path relative to repo root |
| 249 | let normalized = if std::path::Path::new(path).is_absolute() { |
| 250 | match std::path::Path::new(path).strip_prefix(&repo_root) { |
| 251 | Ok(rel) => rel.to_string_lossy().to_string(), |
| 252 | Err(_) => { |
| 253 | print_warning(&format!("Path outside repository: {}", path)); |
| 254 | total_errors += 1; |
| 255 | continue; |
| 256 | } |
| 257 | } |
| 258 | } else { |
| 259 | path.clone() |
| 260 | }; |
| 261 | |
| 262 | if self.dry_run { |
| 263 | println!("Would remove: {}", normalized); |
| 264 | } else { |
| 265 | println!("{}: {}", action, normalized); |
| 266 | } |
| 267 | |
| 268 | // Remove from tracking |
| 269 | match repo.remove(&normalized, options.clone()) { |
| 270 | Ok(stats) => { |
| 271 | total_removed += stats.files_removed; |
| 272 | |
| 273 | // Collect files to delete if not keeping |
| 274 | if self.delete && !self.keep && !self.dry_run { |
| 275 | files_to_delete.push(PathBuf::from(&normalized)); |
| 276 | } |
| 277 | } |
| 278 | Err(e) => { |
| 279 | if !self.force { |
| 280 | print_warning(&format!("Failed to remove '{}': {}", normalized, e)); |
| 281 | total_errors += 1; |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | // Delete files from disk if not keeping |
| 288 | if !self.keep && !self.dry_run { |
| 289 | for path in &files_to_delete { |
| 290 | if let Err(e) = self.delete_file(&repo_root, &path.to_string_lossy()) { |
| 291 | print_warning(&format!("Failed to delete '{}': {}", path.display(), e)); |
nothing calls this directly
no test coverage detected