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

Function sync_git_head_to_view

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

Project the just-materialized Atomic view into its local Git mirror. The working copy is staged exclusively through [`stage_and_validate_tree`]. The Git representation follows the view-scope HEAD policy (RFC §8.1): - **Shared** views map to a `refs/heads/ ` branch and a symbolic HEAD; a local projection commit advances that branch from its prior tip (one parent: the previous projected state

(
    repo: &Repository,
    repo_root: &Path,
    view: &str,
)

Source from the content-addressed store, hash-verified

570/// is active, every failure is returned to the caller and the original Git
571/// HEAD, target ref, and index are restored where possible.
572pub(crate) fn sync_git_head_to_view(
573 repo: &Repository,
574 repo_root: &Path,
575 view: &str,
576) -> CliResult<ShadowSwitchSync> {
577 let git_repo = match GitRepository::discover(repo_root) {
578 Ok(repo) => repo,
579 Err(_) => return Ok(ShadowSwitchSync::SkippedNoGit),
580 };
581 if !shadow_sync_active(&git_repo) {
582 return Ok(ShadowSwitchSync::SkippedInactive);
583 }
584 // A retained shadow exclude line is not enrollment (RFC §2 / CB-13C):
585 // colocated-but-unenrolled repositories keep native view switches with
586 // no Git projection and no checkpoint requirement.
587 if !repo.shim_workspace_active().map_err(CliError::Repository)? {
588 return Ok(ShadowSwitchSync::SkippedInactive);
589 }
590 let working_copy = repo
591 .require_working_copy_id()
592 .map_err(CliError::Repository)?;
593 let desired_view = repo
594 .desired_view_name(working_copy)
595 .map_err(CliError::Repository)?;
596 if desired_view != view {
597 return Err(git_error(format!(
598 "cannot synchronize Git shadow for view '{view}': current Atomic view is '{desired_view}'"
599 )));
600 }
601
602 // A coordinated switch must not silently skip its projection. Contention is
603 // an actionable failure because leaving the old branch/index would publish
604 // stale evidence for the newly materialized view.
605 let shadow_lock = repo
606 .try_lock_shadow_commit()
607 .map_err(CliError::Repository)?
608 .ok_or_else(|| {
609 git_error(
610 "another shadow materialize is in flight; retry the view switch after it completes",
611 )
612 })?;
613
614 let receipt = project_view_to_git_under_shadow_lock(
615 repo,
616 repo_root,
617 &git_repo,
618 view,
619 None,
620 &shadow_lock,
621 )?;
622 // CB-10A: the projection moved the mapped ref under its expected-old
623 // lease; record the fresh Synchronized observation on the held handle.
624 // The verified tip is the live mapped ref tip read under the held shadow
625 // lock (the lease just wrote it).
626 let verified_tip = super::ref_mapping::mapped_ref_tip(&git_repo, repo, view);
627 super::ref_mapping::refresh_mapping_observation(
628 repo,
629 working_copy,

Callers 4

run_two_tierMethod · 0.85
finish_service_switchFunction · 0.85
runMethod · 0.85

Calls 9

shadow_sync_activeFunction · 0.85
mapped_ref_tipFunction · 0.85
shim_workspace_activeMethod · 0.80
desired_view_nameMethod · 0.80
git_errorFunction · 0.70