IndexEntry = (mode: str, hash: str, path: str)
class WorkingTree:
read_index() -> list[IndexEntry] build_tree_from_index() -> str
write_index(entries) -> None diff_working_tree_vs(tree_hash) -> DiffResult
stage_file(path) -> None checkout(tree_hash) -> None
Owner: @Saanvi521
Module: 2 - Index & working tree
File you own:
minigit/index.pyWeek: 1 of 10 - Contract & Skeletons
What "skeleton week" means
Interface contract - exact signatures, do not change alone
"100644"file,"100755"exec,"40000"dir"<mode> <blob-hash> <path>\n", sorted by pathSteps
cd mini-git,scripts/init.sh, skimREADME.md+minigit/errors.pyweek1/m2-working-tree-skeletonIndexEntry(NamedTuple)with mode/hash/path;@dataclass DiffResultwithadded/deleted/modifiedlists (line-level hunks are Week 5 - names only now)__init__(self, repo_path=".", store=None)->self.root,self.index_path,self.store = store or ObjectStore(repo_path),self._entries: list[IndexEntry] = []store=Noneargument is the important part: fake store in tests, real one for free laterread_index->return list(self._entries)(copy, not the live list), always sorted by pathwrite_index->self._entries = sorted(entries, key=lambda e: e.path); no disk write yetstage_file-> read bytes off disk,store.write_object(data, "blob"), replace any entry with the same path, appendIndexEntry("100644", blob_hash, path), re-sortbuild_tree_from_index->return self.store.write_object(b"", "tree")# Week 3 - group by directory, one tree object per level, bottom-updiff_working_tree_vs->return DiffResult()# Week 3 real diff, Week 5 Myerscheckout->pass# Week 4 - write files from a tree, delete the restminigit add <path>,minigit statusminigit/cli.py- one import + one line; expect a small conflicttests/test_index.pywith aFakeObjectStoreclass at the top (dict + len-based hash)tmp_path; cover: staging adds one entry, staging twice replaces not duplicates,read_indexsorted, editing after staging does not change the entryTeam checkpoint (all four, end of week)
build_tree_from_index()andcheckout()-> keep those names exactDone when
IndexEntry+DiffResultdefinedstoreinjectable via__init__