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

Method delete_view

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

492 /// - The view is the current view (cannot delete current view)
493 /// - The database operation fails
494 pub fn delete_view(&mut self, name: &str) -> Result<(), RepositoryError> {
495 // Cannot delete the current view
496 if name == self.current_view {
497 return Err(RepositoryError::CannotDeleteCurrentView {
498 name: name.to_string(),
499 });
500 }
501
502 let mut txn = self
503 .pristine
504 .write_txn()
505 .map_err(|e| RepositoryError::Database(e.to_string()))?;
506
507 // Get the view to delete
508 let view = txn
509 .get_view(name)
510 .map_err(|e| RepositoryError::Database(e.to_string()))?
511 .ok_or_else(|| RepositoryError::ViewNotFound {
512 name: name.to_string(),
513 })?;
514
515 // Delete the view.
516 //
517 // `del_view` enforces:
518 // - Shared views cannot be deleted (returns CannotDeleteSharedView)
519 // - Views with children cannot be deleted (returns ViewHasChildren)
520 // Remove workspace directory for this view before deleting
521 // the view from the database. This cleans up any shelved
522 // artifacts (node_modules, dist, etc.) that were stored when
523 // the user last switched away from this view.
524 let ws = workspace_path(&self.dot_dir, name);
525 if ws.is_dir() {
526 let _ = std::fs::remove_dir_all(&ws);
527 }
528
529 txn.del_view(&view).map_err(|e| match &e {
530 atomic_core::pristine::PristineError::CannotDeleteSharedView { name } => {
531 RepositoryError::InvalidOperation {
532 message: format!(
533 "cannot delete shared view '{}': shared views are permanent. \
534 Use 'view new' to create a draft view instead.",
535 name
536 ),
537 }
538 }
539 atomic_core::pristine::PristineError::ViewHasChildren { name, children } => {
540 RepositoryError::InvalidOperation {
541 message: format!(
542 "cannot delete view '{}': has child views ({}). \
543 Delete or reparent children first.",
544 name,
545 children.join(", ")
546 ),
547 }
548 }
549 _ => RepositoryError::Database(e.to_string()),
550 })?;
551

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