Skip to content

Week 2 - M2: Real index file + working status #11

Description

@aman-a-shah

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

  1. Branch week2/m2-real-index (branch off main after M1 merges)
  2. 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
  3. 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
  4. 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
  5. 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)
  6. 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
  1. build_tree_from_index and checkout stay stubs # Week 3 / Week 4
  2. 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
  3. 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

  • index is a real file, format above
  • state survives across two CLI calls
  • real ObjectStore, no fake
  • status shows staged / not staged / untracked
  • tests cover disk round-trip + spaces in paths
  • quality-check green
  • PR open + reviewed

Activity

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

Metadata

Metadata

Assignees

Labels

module-2Index and working treeweek-2Week 2 - real storage and wire

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions