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

Function resolve_published_binding

atomic-cli/src/commands/git/binding.rs:671–709  ·  view source on GitHub ↗

Resolve a published binding (full id or unambiguous prefix) through the create-only Git refs — not through the local store, so bindings fetched from a Git remote resolve without any local adoption.

(git: &GitRepository, id: &str)

Source from the content-addressed store, hash-verified

669/// create-only Git refs — not through the local store, so bindings fetched
670/// from a Git remote resolve without any local adoption.
671fn resolve_published_binding(git: &GitRepository, id: &str) -> CliResult<GitStateBinding> {
672 let lower = id.to_ascii_lowercase();
673 let mut matches: Vec<GitStateBinding> = Vec::new();
674 let glob = format!("{}*", atomic_repository::BINDING_REF_PREFIX);
675 for reference in git
676 .references_glob(&glob)
677 .map_err(|error| git_map(format!("cannot enumerate binding refs: {error}")))?
678 {
679 let reference = reference.map_err(|error| git_map(error.to_string()))?;
680 // `name()` fails only when the name is not UTF-8. Canonical binding refs
681 // are ASCII by layout, and everything below needs a `&str`, so a stray
682 // non-UTF-8 ref in this namespace is skipped, not fatal.
683 let Ok(name) = reference.name() else {
684 continue;
685 };
686 let Some(target) = reference.target() else {
687 continue;
688 };
689 let binding = load_binding_at_ref(git, name, target)?;
690 if binding.id().to_hex() == lower
691 || (id.len() < 64 && binding.id().to_hex().starts_with(&lower))
692 {
693 matches.push(binding);
694 }
695 }
696 match matches.len() {
697 1 => Ok(matches.remove(0)),
698 0 => Err(CliError::Repository(
699 atomic_repository::RepositoryError::InvalidOperation {
700 message: format!("binding {id} is not published on any refs/atomic/bindings/* ref"),
701 },
702 )),
703 n => Err(CliError::Repository(
704 atomic_repository::RepositoryError::InvalidOperation {
705 message: format!("binding prefix {id} is ambiguous: {n} matches"),
706 },
707 )),
708 }
709}
710
711fn load_binding_at_ref(
712 git: &GitRepository,

Callers 2

fetchFunction · 0.85
resurrectFunction · 0.85

Calls 9

RepositoryClass · 0.85
git_mapFunction · 0.70
load_binding_at_refFunction · 0.70
removeMethod · 0.65
nameMethod · 0.45
to_hexMethod · 0.45
idMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected