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

Function adopt_from_remote

libatomic/src/identity_transport.rs:290–311  ·  view source on GitHub ↗

Explicit divergence remediation (`atomic repo identity adopt`): fetch the remote's binding and unconditionally replace the local identity, then rebuild the derived KG under the adopted id. Errors when the remote has no binding (or predates the transport) — there is nothing to adopt.

(
    repo: &Repository,
    remote: &HttpRemote,
)

Source from the content-addressed store, hash-verified

288/// rebuild the derived KG under the adopted id. Errors when the remote has no
289/// binding (or predates the transport) — there is nothing to adopt.
290pub async fn adopt_from_remote(
291 repo: &Repository,
292 remote: &HttpRemote,
293) -> Result<String, RepositoryError> {
294 let Some(document) = fetch_identity(remote).await? else {
295 return Err(RepositoryError::InvalidOperation {
296 message: "remote has no bound project identity to adopt".into(),
297 });
298 };
299 let record = record_from_document(&document)
300 .map_err(|e| RepositoryError::InvalidOperation { message: e })?;
301 let adopted = repo.force_adopt_remote_identity(&record)?;
302 let project_id = adopted
303 .project_id()
304 .map_err(|e| RepositoryError::InvalidOperation {
305 message: e.to_string(),
306 })?
307 .to_base32();
308 // The adopted id re-keys every project-qualified IRI.
309 repo.rebuild_kg(false)?;
310 Ok(project_id)
311}
312
313#[cfg(test)]
314mod tests {

Callers 1

adoptMethod · 0.85

Calls 6

fetch_identityFunction · 0.85
record_from_documentFunction · 0.85
rebuild_kgMethod · 0.80
to_base32Method · 0.45
project_idMethod · 0.45

Tested by

no test coverage detected