Loading...
avatar

Humbulan
Python
joined 12 days ago
  1. Project Goal and Demonstrated Insight Goal: To implement a basic Git clone operation entirely within a shell script, accurately following the Git Smart HTTP Protocol (Git's network protocol). Insight Demonstrated: This project required understanding and handling the complexities of a binary application-layer network protocol. Specifically, it demonstrates mastery over:
  • Binary Protocol Parsing: Sending raw HTTP requests and correctly interpreting the structure of the Git \mathbf{pkt-line} (packet-line) format in the server's binary response.
  • Data Extraction: Developing robust \mathbf{regular\ expressions} to accurately locate and extract critical 40-character \mathbf{SHA-1\ hashes} from the noisy protocol data stream.
  • Low-Level System Integration: Orchestrating core Linux utilities (curl, grep, printf, etc.) and Git internals (git unpack-objects) to successfully download and reconstruct the complete repository structure.
  1. Final Script Code The final production script, mygitcloneperfected.sh (or mygitcloneproduction.sh), is omitted for brevity but is submitted separately. The script successfully handles initialization, capability discovery, hash extraction, packfile negotiation, and object unpacking.
  2. Demonstration Log: Successful Repository Clone The following log confirms the successful cloning of a public Git repository. A. Execution of the Clone Command $ ./mygitcloneperfected.sh clone https://github.com/octocat/Hello-World codecrafterstest Repository: octocat/Hello-World Target directory: codecrafterstest === Git Clone Implementation === Cloning into 'codecrafterstest'… Working in: /data/data/com.termux/files/home/codecrafterstest Step 1: Initializing git directory… Git directory initialized Step 2: Discovering server capabilities… Fetching from: https://github.com/octocat/Hello-World.git/info/refs?service=git-upload-pack Binary response received: 142733 bytes Step 3: Extracting master branch hash… Searching for master branch reference… Found master line: 003f7fd1a60b01f91b314f59955a4e4d4e80d8edf11d refs/heads/master Master branch hash: 7fd1a60b01f91b314f59955a4e4d4e80d8edf11d Step 4: Preparing negotiation request… Using master branch hash: 7fd1a60b01f91b314f59955a4e4d4e80d8edf11d Binary request prepared: 63 bytes Step 5: Downloading packfile… POST to: https://github.com/octocat/Hello-World.git/git-upload-pack Response received: 708 bytes Found packfile at offset: 8 Packfile extracted: 700 bytes Packfile signature verified Step 6: Unpacking objects… Objects unpacked successfully: 7 objects Step 7: Checking out files… Checking out master branch: 7fd1a60b01f91b314f59955a4e4d4e80d8edf11d Checkout completed successfully Step 8: Cleaning up temporary files… === Clone completed successfully! === Repository: codecrafterstest Branch: master

B. Verification of Cloned Repository Integrity The verification steps confirm that the cloned directory is a fully functioning Git repository, complete with the correct file content and commit history. $ cd codecrafters_test

1. Verify File Content

$ cat README Hello World!

2. Verify Git History (Must match the remote repository's history)

$ git log --oneline 7fd1a60 (HEAD, master) Merge pull request #6 from Spaceghost/patch-1 7629413 New line at end of file. --Signed off by Spaceghost 553c207 first commit

  1. Error Handling Demonstration (Robustness) The script includes necessary error handling to check HTTP status codes, preventing execution failures when a repository is inaccessible or non-existent.

Test with a non-existent repository (simulating a 401 or 404 error)

$ ./mygitcloneproduction.sh clone https://github.com/user/repo testnonexistent Repository: user/repo … Step 2: Discovering server capabilities… Fetching from: https://github.com/user/repo.git/info/refs?service=git-upload-pack Response received: 21 bytes (HTTP 401) Error: Failed to access repository (HTTP 401) Server message: [… Error message correctly extracted from minimal response …]

Challenges

Build your own HTTP server
using Python
Build your own HTTP server
Learn about TCP servers, the HTTP protocol and more
completed
Python
Build your own DNS server
using Python
Build your own DNS server
Learn about the DNS protocol, DNS record types and more.
completed
Python
Build your own Redis
using Python
Build your own Redis
Learn about TCP servers, the Redis protocol and more
16/89 stages
Python
Build your own grep
using Python
Build your own grep
Learn about regex syntax: character classes, quantifiers and more
14/23 stages
Python
Build your own BitTorrent
using Python
Build your own BitTorrent
Learn about .torrent files, the BitTorrent Peer Protocol and more
13/19 stages
Python
Build your own Kafka
using Python
Build your own Kafka
Learn about TCP servers, the Kafka wire protocol and more.
5/25 stages
Python
Build your own Interpreter
using Python
Build your own Interpreter
Learn about tokenization, ASTs, tree-walk interpreters and more.
34/84 stages
Python
Build your own Git
using Python
Build your own Git
Learn about git objects, plumbing commands and more
6/7 stages
Python
Build your own SQLite
using Python
Build your own SQLite
Learn about SQL syntax, SQLite's file format, B-trees and more
7/9 stages
Python
Build your own Shell
using Python
Build your own Shell
Learn about parsing shell commands, executing programs and more
26/43 stages
Python
October 2025