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

Method delete_view

atomic-repository/src/repository/views.rs:401–463  ·  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

399 /// - The view is the current view (cannot delete current view)
400 /// - The database operation fails
401 pub fn delete_view(&mut self, name: &str) -> Result<(), RepositoryError> {
402 // Cannot delete the current view
403 if name == self.current_view {
404 return Err(RepositoryError::CannotDeleteCurrentView {
405 name: name.to_string(),
406 });
407 }
408
409 let mut txn = self
410 .pristine
411 .write_txn()
412 .map_err(|e| RepositoryError::Database(e.to_string()))?;
413
414 // Get the view to delete
415 let view = txn
416 .get_view(name)
417 .map_err(|e| RepositoryError::Database(e.to_string()))?
418 .ok_or_else(|| RepositoryError::ViewNotFound {
419 name: name.to_string(),
420 })?;
421
422 // Delete the view.
423 //
424 // `del_view` enforces:
425 // - Shared views cannot be deleted (returns CannotDeleteSharedView)
426 // - Views with children cannot be deleted (returns ViewHasChildren)
427 // Remove workspace directory for this view before deleting
428 // the view from the database. This cleans up any shelved
429 // artifacts (node_modules, dist, etc.) that were stored when
430 // the user last switched away from this view.
431 let ws = workspace_path(&self.dot_dir, name);
432 if ws.is_dir() {
433 let _ = std::fs::remove_dir_all(&ws);
434 }
435
436 txn.del_view(&view).map_err(|e| match &e {
437 atomic_core::pristine::PristineError::CannotDeleteSharedView { name } => {
438 RepositoryError::InvalidOperation {
439 message: format!(
440 "cannot delete shared view '{}': shared views are permanent. \
441 Use 'view new' to create a draft view instead.",
442 name
443 ),
444 }
445 }
446 atomic_core::pristine::PristineError::ViewHasChildren { name, children } => {
447 RepositoryError::InvalidOperation {
448 message: format!(
449 "cannot delete view '{}': has child views ({}). \
450 Delete or reparent children first.",
451 name,
452 children.join(", ")
453 ),
454 }
455 }
456 _ => RepositoryError::Database(e.to_string()),
457 })?;
458

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