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

Method remove

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

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,
    )

Source from the content-addressed store, hash-verified

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()

Callers

nothing calls this directly

Calls 10

is_trackedFunction · 0.85
tracked_under_prefixFunction · 0.85
get_inodeFunction · 0.85
remove_from_treeFunction · 0.85
as_refMethod · 0.80
write_txnMethod · 0.80
commitMethod · 0.80
normalize_pathFunction · 0.50
is_emptyMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected