Bind the local identity to the remote before a push, refusing a push that would land on a project bound to a *different* identity. Pass the local record when the repository has one; `None` (no local identity) is a no-op.
(
local: &ProjectIdentityRecord,
remote: &HttpRemote,
)
| 255 | /// would land on a project bound to a *different* identity. Pass the local |
| 256 | /// record when the repository has one; `None` (no local identity) is a no-op. |
| 257 | pub async fn bind_before_push( |
| 258 | local: &ProjectIdentityRecord, |
| 259 | remote: &HttpRemote, |
| 260 | ) -> Result<PushBind, RepositoryError> { |
| 261 | let document: serde_json::Value = |
| 262 | serde_json::from_slice(&local.object).map_err(|e| RepositoryError::InvalidOperation { |
| 263 | message: format!("local identity is not valid JSON: {e}"), |
| 264 | })?; |
| 265 | let local_id = local |
| 266 | .project_id() |
| 267 | .map_err(|e| RepositoryError::InvalidOperation { |
| 268 | message: e.to_string(), |
| 269 | })? |
| 270 | .to_base32(); |
| 271 | |
| 272 | match remote |
| 273 | .bind_project_identity(&document) |
| 274 | .await |
| 275 | .map_err(|error| RepositoryError::InvalidOperation { |
| 276 | message: format!("project-identity bind failed: {error}"), |
| 277 | })? { |
| 278 | BindOutcome::Bound => Ok(PushBind::Bound(local_id)), |
| 279 | BindOutcome::Unsupported => Ok(PushBind::Unsupported), |
| 280 | BindOutcome::Conflict { remote, server } => Err(RepositoryError::InvalidOperation { |
| 281 | message: format_bind_conflict(&local_id, &remote, server.as_ref()), |
| 282 | }), |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | /// Explicit divergence remediation (`atomic repo identity adopt`): fetch the |
| 287 | /// remote's binding and unconditionally replace the local identity, then |
no test coverage detected