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

Method delete_view

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

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

Callers 8

run_popMethod · 0.80
run_dropMethod · 0.80
run_clearMethod · 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