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
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.
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.
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.
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.
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.
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.
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
Owner: @Shuhan6017
Files:
minigit/remote.py,tests/test_remote.pyDepends on: #19, #22 (
has_object), #24 (is_ancestor)Branch:
week4/m4-single-branch-pushMake
minigit push <address> <branch> --token <token>copy missing objects and update one remote branch.Steps
mainafter Week 3 - M4: Multi-object transfer + reachable objects #19 merges. Construct real M1/M3 instances when dependencies are not injected.REF;-means the branch does not exist.NetworkProtocolError.PUSH <branch> <old-hash|-> <new-hash>: server checks the expected old ref; repliesOKorERR <reason>.HAVE <hash>: server callshas_object; repliesYESorNO.PUT <hash>: client follows with Week 3'sOBJ <type> <len>\nand exactly<len>raw bytes. Server verifies, stores, then repliesOK.DONE: server validates the new history, updates the ref, repliesOK, and closes the push session.collect_reachable(branch)for the commit/tree/blob set. AskHAVEfor each unique hash and upload only missing objects.recv_exact.write_object. Route all object access through M1.OK. Protocol, auth, object-validation, and connection failures becomeNetworkProtocolError.scripts/quality-check.sh. Open a PR linked to this issue and request a teammate review.Tests
DONEleaves the ref unchanged.0, timeouts, and reliable server shutdown.Pull and broader conflict handling remain in Weeks 5-6.
Done when