Skip to main content

update_ref_checked

Function update_ref_checked 

Source
pub fn update_ref_checked(
    repo: &Path,
    ref_name: &str,
    new_sha: &str,
    old: Option<&str>,
) -> Result<(), SyncError>
Expand description

Points a ref at a commit only if it currently holds the expected value.

This is a compare-and-swap: it runs git update-ref <ref> <new> <old>, where old is the value the ref must currently hold. When old is None, the all-zeros OID (ZERO_OID) is used to assert the ref must not yet exist. Git performs the comparison and the update atomically under a ref lock, so two concurrent syncs in the same repo cannot silently clobber each other.

On a mismatch (the ref moved or already exists) this returns SyncError::RefCasMismatch so a caller can re-read the ref and retry. Any other failure is reported as SyncError::Git.