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

Method delete_view

atomic-repository/src/repository/views.rs:439–501  ·  view source on GitHub ↗

Delete a view from the repository. This removes the view and all its associated metadata, but does not delete the changes themselves. Changes remain in the graph and may be referenced by other views. # Arguments `name` - The name of the view to delete # Errors Returns an error if: - The view does not exist - The view is the current view (cannot delete current view) - The database operation fa

(&mut self, name: &str)

Source from the content-addressed store, hash-verified

437 /// - The view is the current view (cannot delete current view)
438 /// - The database operation fails
439 pub fn delete_view(&mut self, name: &str) -> Result<(), RepositoryError> {
440 // Cannot delete the current view
441 if name == self.current_view {
442 return Err(RepositoryError::CannotDeleteCurrentView {
443 name: name.to_string(),
444 });
445 }
446
447 let mut txn = self
448 .pristine
449 .write_txn()
450 .map_err(|e| RepositoryError::Database(e.to_string()))?;
451
452 // Get the view to delete
453 let view = txn
454 .get_view(name)
455 .map_err(|e| RepositoryError::Database(e.to_string()))?
456 .ok_or_else(|| RepositoryError::ViewNotFound {
457 name: name.to_string(),
458 })?;
459
460 // Delete the view.
461 //
462 // `del_view` enforces:
463 // - Shared views cannot be deleted (returns CannotDeleteSharedView)
464 // - Views with children cannot be deleted (returns ViewHasChildren)
465 // Remove workspace directory for this view before deleting
466 // the view from the database. This cleans up any shelved
467 // artifacts (node_modules, dist, etc.) that were stored when
468 // the user last switched away from this view.
469 let ws = workspace_path(&self.dot_dir, name);
470 if ws.is_dir() {
471 let _ = std::fs::remove_dir_all(&ws);
472 }
473
474 txn.del_view(&view).map_err(|e| match &e {
475 atomic_core::pristine::PristineError::CannotDeleteSharedView { name } => {
476 RepositoryError::InvalidOperation {
477 message: format!(
478 "cannot delete shared view '{}': shared views are permanent. \
479 Use 'view new' to create a draft view instead.",
480 name
481 ),
482 }
483 }
484 atomic_core::pristine::PristineError::ViewHasChildren { name, children } => {
485 RepositoryError::InvalidOperation {
486 message: format!(
487 "cannot delete view '{}': has child views ({}). \
488 Delete or reparent children first.",
489 name,
490 children.join(", ")
491 ),
492 }
493 }
494 _ => RepositoryError::Database(e.to_string()),
495 })?;
496

Callers 10

run_popMethod · 0.80
run_dropMethod · 0.80
run_clearMethod · 0.80
remove_park_viewMethod · 0.80
runMethod · 0.80
test_delete_viewFunction · 0.80

Calls 6

workspace_pathFunction · 0.85
write_txnMethod · 0.80
is_dirMethod · 0.80
del_viewMethod · 0.80
commitMethod · 0.80
get_viewMethod · 0.45

Tested by 4

test_delete_viewFunction · 0.64