Remove a file or directory from tracking. This removes the file from version control tracking. It does NOT delete the file from disk. # Arguments `path` - Path to remove from tracking `options` - Options controlling the remove operation # Example ```rust,ignore // Remove a single file repo.remove("old_file.txt", TrackingOptions::default())?; // Remove a directory recursively repo.remove("old
(
&self,
path: P,
options: TrackingOptions,
)
| 337 | /// repo.remove("old_dir/", TrackingOptions::default())?; |
| 338 | /// ``` |
| 339 | pub fn remove<P: AsRef<Path>>( |
| 340 | &self, |
| 341 | path: P, |
| 342 | options: TrackingOptions, |
| 343 | ) -> Result<TrackingStats, RepositoryError> { |
| 344 | let path = path.as_ref(); |
| 345 | let mut stats = TrackingStats::new(); |
| 346 | let normalized = normalize_path(path); |
| 347 | |
| 348 | let mut txn = self |
| 349 | .pristine |
| 350 | .write_txn() |
| 351 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 352 | |
| 353 | // Check if the path is tracked first (for non-recursive case) |
| 354 | let _is_path_tracked = |
| 355 | is_tracked(&txn, &normalized).map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 356 | |
| 357 | // Get all files under this path if recursive |
| 358 | let to_remove = if options.recursive { |
| 359 | let files = tracked_under_prefix(&txn, &normalized) |
| 360 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 361 | |
| 362 | // If no files found and not forced, error |
| 363 | if files.is_empty() && !options.force { |
| 364 | return Err(RepositoryError::FileNotTracked { |
| 365 | path: path.to_path_buf(), |
| 366 | }); |
| 367 | } |
| 368 | files |
| 369 | } else { |
| 370 | // Just the single path |
| 371 | if let Some(inode) = get_inode(&txn, &normalized) |
| 372 | .map_err(|e| RepositoryError::Database(e.to_string()))? |
| 373 | { |
| 374 | vec![(normalized.clone(), inode)] |
| 375 | } else { |
| 376 | if !options.force { |
| 377 | return Err(RepositoryError::FileNotTracked { |
| 378 | path: path.to_path_buf(), |
| 379 | }); |
| 380 | } |
| 381 | vec![] |
| 382 | } |
| 383 | }; |
| 384 | |
| 385 | if options.dry_run { |
| 386 | stats.files_removed = to_remove.len(); |
| 387 | return Ok(stats); |
| 388 | } |
| 389 | |
| 390 | for (file_path, _inode) in to_remove { |
| 391 | remove_from_tree(&mut txn, &file_path) |
| 392 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 393 | stats.files_removed += 1; |
| 394 | } |
| 395 | |
| 396 | txn.commit() |
nothing calls this directly
no test coverage detected