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,
)
| 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. |
| 290 | pub 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)] |
| 314 | mod tests { |
no test coverage detected