Skip to main content

push_remote

Function push_remote 

Source
pub fn push_remote(
    local_git_dir: &Path,
    conn: &mut dyn Connection,
    refs: &[PushRefSpec],
    opts: &PushOptions,
    progress: &mut dyn Progress,
) -> Result<PushOutcome>
Expand description

Push refs to a remote over a live Connection speaking git-receive-pack.

The flow mirrors crate::transfer::push_local, but the remote ref list and .have hints come from the connection’s advertisement, the objects are streamed over the wire as a single pack, and per-ref acceptance/rejection is learned from the server’s report-status reply (a server may reject an update our local checks would have accepted, e.g. denyNonFastForwards or a pre-receive hook).

Steps:

  1. Read the receive-pack advertisement from conn: remote refs (name -> oid), .have oids, and capabilities (report-status(-v2), side-band-64k, ofs-delta, object-format).
  2. Decide each PushRefSpec against the advertised remote refs (up-to-date, new, fast-forward, forced, non-fast-forward rejection, force-with-lease stale) — the client-side gate before anything is sent.
  3. Write the ref-update commands for the accepted, value-changing updates (<old> <new> <ref>\0<caps>\n first, <old> <new> <ref>\n rest), then a flush.
  4. Build the minimal pack with build_pack (wants = new tips, haves = advertised remote tips + .haves) and stream it; for deletion-only pushes stream the empty pack.
  5. Read + parse report-status / report-status-v2 (demultiplexing the side-band if negotiated) and fold the per-ref ok/ng lines back into the decided results.

progress receives the remote’s side-band channel-2 bytes (hook output, remote: … diagnostics) when side-band-64k is negotiated.

Protocol v0/v1 only; a v2 connection is rejected.

§Errors

Returns an error if the connection is protocol v2, if a source object is missing from the local odb, if the pack build fails, or on wire/parse I/O failure.