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

Function sync_inherited_agent_view

atomic-cli/src/commands/git/shadow.rs:645–756  ·  view source on GitHub ↗

Selecting an inherited agent view does not materialize the worktree. Reuse its already verified Git tree and preserve both staged and unstaged edits. This narrower transition is valid only for identical closures. Unenrolled working copies are native: a `.git` directory (or a retained shadow exclude line) is not shim consent (RFC §2 / CB-13C), so they skip the Git-side coordination entirely instea

(root: &Path, view: &str)

Source from the content-addressed store, hash-verified

643/// shadow exclude line) is not shim consent (RFC §2 / CB-13C), so they skip
644/// the Git-side coordination entirely instead of demanding a checkpoint.
645pub(crate) fn sync_inherited_agent_view(root: &Path, view: &str) -> CliResult<()> {
646 let git = match GitRepository::open(root) {
647 Ok(git) if shadow_sync_active(&git) => git,
648 _ => return Ok(()),
649 };
650 let repo = Repository::open_for_workspace_transaction_wait(
651 root,
652 atomic_repository::database_lock_wait(),
653 )
654 .map_err(CliError::Repository)?;
655 // Enrollment is checkpoint-or-explicit-opt-in (the same predicate every
656 // workspace boundary uses). The retained exclude marker alone must never
657 // make a native agent session require a shim checkpoint.
658 if !repo.shim_workspace_active().map_err(CliError::Repository)? {
659 return Ok(());
660 }
661 let Some(before) = super::checkpoint::read_checkpoint(root).map_err(checkpoint_error_of)?
662 else {
663 // Enrolled but not anchored. Selecting the view would move Git
664 // HEAD/refs — a shim-specific destructive operation — so it fails
665 // closed with the shared anchor-or-disable remediation rather than a
666 // bare internal error.
667 return Err(CliError::StaleBaseline {
668 report: format!(
669 "agent view selection on an enrolled but unanchored Git shim: {}",
670 atomic_repository::UnanchoredWorkspace::MissingCheckpoint
671 .remediation()
672 .unwrap_or_default()
673 ),
674 });
675 };
676 let old = repo
677 .view_identity(&before.view)
678 .map_err(CliError::Repository)?;
679 let new = repo.view_identity(view).map_err(CliError::Repository)?;
680 if old.set_id != new.set_id
681 || old.closure_len != new.closure_len
682 || old.merkle.to_base32() != before.atomic_state
683 {
684 drop(repo);
685 return crate::commands::view::switch::finish_service_switch(root, view);
686 }
687 let common = repo
688 .try_lock_shadow_commit()
689 .map_err(CliError::Repository)?
690 .ok_or_else(|| git_error("another Git projection is in flight; retry agent startup"))?;
691 let head = git
692 .head()
693 .and_then(|h| h.peel_to_commit())
694 .map_err(|e| git_error(e.to_string()))?;
695 if head.id().to_string() != before.git_head || head.tree_id().to_string() != before.git_tree {
696 return Err(git_error("Git HEAD changed during agent view selection"));
697 }
698 let (policy, _) = current_conversion_policy(root, &git)?;
699 let project = repo
700 .project_tree(view, &policy)
701 .map_err(|e| git_error(e.to_string()))?;
702 if project.git.root.as_bytes() != head.tree_id().as_bytes() {

Calls 15

openFunction · 0.85
shadow_sync_activeFunction · 0.85
database_lock_waitFunction · 0.85
read_checkpointFunction · 0.85
finish_service_switchFunction · 0.85
resolve_head_policyFunction · 0.85
to_core_oidFunction · 0.85
shim_workspace_activeMethod · 0.80
view_identityMethod · 0.80