Owner:@Saanvi521
Module: 2 - Index & working tree
File you own:minigit/index.py
Week: 2 of 10 - Real Bytes on Disk
What changes this week
- Week 1 index lived in
self._entries and vanished when the process exited - Week 2 the index is a real file:
.minigit/index minigit add then minigit status in two separate commands must now work- @mahis1067's real
ObjectStore lands this week - use it, stop faking blobs
Index file format - exact, do not change alone
<mode> <blob-hash> <path>\n
- one line per entry, sorted by path, UTF-8, trailing
\n on every line - paths are repo-relative and use
/ (src/utils/parse.py), never absolute
Steps
- Branch
week2/m2-real-index (branch off main after M1 merges) read_index -> index file missing = return []; else parse each line with line.split(" ", 2) -> IndexEntry, return sorted by path
split(" ", 2) and not plain split() - filenames can contain spaces
write_index -> sort by path, join lines, mkdir(parents=True, exist_ok=True), write the file
- drop
self._entries entirely; the file is now the only state
stage_file(path):
- normalise to a repo-relative path, missing file ->
MiniGitError - read bytes ->
self.store.write_object(data, "blob") read_index, drop any entry with the same path, append IndexEntry("100644", blob_hash, path), write_index- executable bit set on disk -> mode
"100755" (os.access(p, os.X_OK)) - snapshot rule still holds: editing the file after staging does not change the index
diff_working_tree_vs stays a stub, but make it real against the index for status:
- add
_working_status() -> DiffResult - for each index entry, re-hash the file on disk
- file gone ->
deleted - hash differs ->
modified - files on disk not in the index and not under
.minigit/ -> added (untracked)
minigit status prints, in this order, one path per line:
staged:
<path>
not staged:
<path>
untracked:
<path>
- nothing in a section -> skip the whole section; nothing at all -> print
clean
build_tree_from_index and checkout stay stubs # Week 3 / Week 4- Tests
tests/test_index.py - delete FakeObjectStore, use the real ObjectStore(tmp_path):
- stage a file, new
WorkingTree on the same path, read_index still has it - staging twice replaces, does not duplicate
- index file on disk has exactly one line, sorted order across two files
- path with a space round-trips
- edit after staging -> shows up as
not staged, index hash unchanged - untracked file appears in
untracked - deleting a staged file ->
deleted
- quality-check green -> commit, push, PR
Notes
- run
minigit init first in tests (tmp_path), or create .minigit/ yourself - @DanisLol calls
build_tree_from_index() and checkout() - names stay exact
Done when
Owner:@Saanvi521
Module: 2 - Index & working tree
File you own:
minigit/index.pyWeek: 2 of 10 - Real Bytes on Disk
What changes this week
self._entriesand vanished when the process exited.minigit/indexminigit addthenminigit statusin two separate commands must now workObjectStorelands this week - use it, stop faking blobsIndex file format - exact, do not change alone
\non every line/(src/utils/parse.py), never absoluteSteps
week2/m2-real-index(branch offmainafter M1 merges)read_index-> index file missing = return[]; else parse each line withline.split(" ", 2)->IndexEntry, return sorted by pathsplit(" ", 2)and not plainsplit()- filenames can contain spaceswrite_index-> sort by path, join lines,mkdir(parents=True, exist_ok=True), write the fileself._entriesentirely; the file is now the only statestage_file(path):MiniGitErrorself.store.write_object(data, "blob")read_index, drop any entry with the same path, appendIndexEntry("100644", blob_hash, path),write_index"100755"(os.access(p, os.X_OK))diff_working_tree_vsstays a stub, but make it real against the index forstatus:_working_status() -> DiffResult- for each index entry, re-hash the file on diskdeletedmodified.minigit/->added(untracked)minigit statusprints, in this order, one path per line:cleanbuild_tree_from_indexandcheckoutstay stubs# Week 3 / Week 4tests/test_index.py- deleteFakeObjectStore, use the realObjectStore(tmp_path):WorkingTreeon the same path,read_indexstill has itnot staged, index hash unchangeduntrackeddeletedNotes
minigit initfirst in tests (tmp_path), or create.minigit/yourselfbuild_tree_from_index()andcheckout()- names stay exactDone when
ObjectStore, no fakestatusshows staged / not staged / untracked