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

Method reconcile_scaffold_view

atomic-cli/src/commands/clone/command.rs:610–656  ·  view source on GitHub ↗

Remove an empty locally-created view whose identity conflicts with the manifest about to be applied. `Repository::init` pre-creates a shared root view (e.g. "dev"). If the remote's view of the same name is a draft or has a parent, `apply_view_manifest` would report an identity mismatch even though the local view is just an empty scaffold. Deleting the scaffold lets the manifest recreate the view

(
        &self,
        repo: &mut Repository,
        manifest: &ViewManifest,
    )

Source from the content-addressed store, hash-verified

608 /// Views with changes are left alone: a genuine divergence must surface
609 /// as an apply error, never a silent delete.
610 fn reconcile_scaffold_view(
611 &self,
612 repo: &mut Repository,
613 manifest: &ViewManifest,
614 ) -> CliResult<()> {
615 if !repo
616 .view_exists(&manifest.name)
617 .map_err(CliError::Repository)?
618 {
619 return Ok(());
620 }
621 let info = repo
622 .get_view_info(&manifest.name)
623 .map_err(CliError::Repository)?;
624 if info.scope == manifest.scope && info.parent_name == manifest.parent {
625 // Identity matches; apply_view_manifest handles the log.
626 return Ok(());
627 }
628 if info.change_count > 0 {
629 // Not a scaffold; let apply_view_manifest report the mismatch.
630 return Ok(());
631 }
632
633 // The scaffold may be the current view (init leaves it current),
634 // and the current view cannot be deleted — park on a temporary
635 // root view first. It is removed again before clone finishes.
636 if repo.current_view() == manifest.name {
637 if !repo
638 .view_exists(SCAFFOLD_PARK_VIEW)
639 .map_err(CliError::Repository)?
640 {
641 repo.create_shared_view(SCAFFOLD_PARK_VIEW)
642 .map_err(CliError::Repository)?;
643 }
644 repo.align_to_view(SCAFFOLD_PARK_VIEW)
645 .map_err(CliError::Repository)?;
646 }
647
648 // Shared views cannot be deleted directly; demote first.
649 if info.scope.is_shared() {
650 repo.set_view_scope(&manifest.name, ViewScope::Draft)
651 .map_err(CliError::Repository)?;
652 }
653 repo.delete_view(&manifest.name)
654 .map_err(CliError::Repository)?;
655 Ok(())
656 }
657
658 /// Remove the temporary parking view, if scaffold reconciliation
659 /// created it. Best-effort: a leftover parking view is cosmetic.

Callers 2

apply_manifestsMethod · 0.80

Calls 8

view_existsMethod · 0.80
get_view_infoMethod · 0.80
current_viewMethod · 0.80
create_shared_viewMethod · 0.80
align_to_viewMethod · 0.80
is_sharedMethod · 0.80
set_view_scopeMethod · 0.80
delete_viewMethod · 0.80

Tested by

no test coverage detected