Skip to content

Week 4 - M4: Ref exchange + single-branch push #25

Description

@aman-a-shah

Owner: @Shuhan6017
Files: minigit/remote.py, tests/test_remote.py
Depends on: #19, #22 (has_object), #24 (is_ancestor)
Branch: week4/m4-single-branch-push

Make minigit push <address> <branch> --token <token> copy missing objects and update one remote branch.

Steps

  1. Start from updated main after Week 3 - M4: Multi-object transfer + reachable objects #19 merges. Construct real M1/M3 instances when dependencies are not injected.
  2. Resolve the local branch tip and authenticate. Read the remote tip through REF; - means the branch does not exist.
    • Missing local branch: raise NetworkProtocolError.
    • Matching tips: report up to date.
    • For an existing remote tip, require it to be a known ancestor of the local tip. Otherwise reject the push.
  3. Document and implement this sequence after AUTH/REF:
    • PUSH <branch> <old-hash|-> <new-hash>: server checks the expected old ref; replies OK or ERR <reason>.
    • HAVE <hash>: server calls has_object; replies YES or NO.
    • PUT <hash>: client follows with Week 3's OBJ <type> <len>\n and exactly <len> raw bytes. Server verifies, stores, then replies OK.
    • DONE: server validates the new history, updates the ref, replies OK, and closes the push session.
  4. Use collect_reachable(branch) for the commit/tree/blob set. Ask HAVE for each unique hash and upload only missing objects.
    • Reuse the shared receive buffer and recv_exact.
    • Hash-check each upload before write_object. Route all object access through M1.
  5. Before updating the ref, verify every referenced commit, tree, and blob exists with the expected type. Recheck the old ref and fast-forward condition.
    • Use M3 for ref reads, ancestry checks, and the final ref write.
    • Keep HEAD, index, and working files unchanged on the server.
  6. Report success only after the final OK. Protocol, auth, object-validation, and connection failures become NetworkProtocolError.
    • A transfer failure leaves the old ref intact. Complete objects already received can stay for retry.
  7. Run scripts/quality-check.sh. Open a PR linked to this issue and request a teammate review.

Tests

  • Push nested files and multiple commits between two temporary repos.
  • Push to an empty branch, then push one more commit.
  • Repeat the same push; transfer no objects.
  • Shared blobs transfer once; the receiver can read the full history through fresh M1/M3 instances.
  • Bad auth, bad payload, or disconnect before DONE leaves the ref unchanged.
  • Reject an unrelated remote tip and a ref changed during transfer.
  • Use loopback, port 0, timeouts, and reliable server shutdown.

Pull and broader conflict handling remain in Weeks 5-6.

Done when

  • First and incremental pushes update one remote branch.
  • Only missing objects transfer.
  • Ref moves after all required objects validate.
  • Quality check passes; PR open and review requested.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

module-4Remotes and networkingweek-4Week 4 - branching and checkout

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions