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

Function bind_before_push

libatomic/src/identity_transport.rs:257–284  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

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.
257pub 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

Callers 2

run_asyncMethod · 0.85
push_changes_implFunction · 0.85

Calls 5

format_bind_conflictFunction · 0.85
bind_project_identityMethod · 0.80
as_refMethod · 0.80
to_base32Method · 0.45
project_idMethod · 0.45

Tested by

no test coverage detected