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

Method delete_view

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

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

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