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

Function exact_managed_commit_at

atomic-cli/src/commands/agent/hooks.rs:636–685  ·  view source on GitHub ↗

[`exact_managed_commit`] with the reason a commit does not qualify.

(
    repository: &Repository,
    repository_root: &std::path::Path,
    session_id: &str,
    head_oid: &str,
)

Source from the content-addressed store, hash-verified

634
635/// [`exact_managed_commit`] with the reason a commit does not qualify.
636fn exact_managed_commit_at(
637 repository: &Repository,
638 repository_root: &std::path::Path,
639 session_id: &str,
640 head_oid: &str,
641) -> Result<atomic_agent::record::ExactManagedCommit, String> {
642 let sessions = Repository::canonical_dot_dir(repository_root)
643 .map_err(|error| format!("session store unavailable: {error}"))?
644 .join("sessions");
645 let session = atomic_agent::turn::session::SessionStore::new(sessions)
646 .and_then(|store| store.load(session_id))
647 .map_err(|error| format!("cannot load the session: {error}"))?
648 .ok_or("the session has no durable record")?;
649 // An incomplete session is terminal until repaired (first writer wins).
650 if session.incomplete().is_some() {
651 return Err("the session is already incomplete".to_string());
652 }
653 let commit = atomic_agent::record::exact_managed_commit_at_turn_end(
654 repository,
655 repository_root,
656 &session,
657 )
658 .ok_or("the commit is not exactly this turn's work")?;
659 if commit.commit_oid != head_oid {
660 return Err(format!("HEAD moved again to {}", commit.commit_oid));
661 }
662 let checkpoint = crate::commands::git::checkpoint::read_checkpoint(repository_root)
663 .map_err(|error| format!("cannot read the shim checkpoint: {error}"))?
664 .ok_or("there is no verified shim checkpoint")?;
665 if checkpoint.git_head_symref.is_some()
666 || checkpoint.git_head != commit.parent_oid
667 || checkpoint.view != session.view_name
668 {
669 return Err(format!(
670 "the checkpoint names view '{}' at {}, not the session view '{}' at the \
671 commit's parent {}",
672 checkpoint.view, checkpoint.git_head, session.view_name, commit.parent_oid
673 ));
674 }
675 let single_child = git2::Repository::open(repository_root)
676 .and_then(|git| {
677 let head = git.find_commit(git2::Oid::from_str(&commit.commit_oid)?)?;
678 Ok(head.parent_count() == 1 && head.parent_id(0)?.to_string() == commit.parent_oid)
679 })
680 .map_err(|error| format!("cannot read the commit: {error}"))?;
681 if !single_child {
682 return Err("the commit is not the single direct child of the turn's start".to_string());
683 }
684 Ok(commit)
685}
686
687/// Finish an adoption an earlier hook recorded but could not complete.
688///

Callers 1

exact_managed_commitFunction · 0.85

Calls 5

read_checkpointFunction · 0.85
openFunction · 0.50
loadMethod · 0.45
incompleteMethod · 0.45

Tested by

no test coverage detected