Skip to main content

status_diff

Function status_diff 

Source
pub fn status_diff(
    store: &ObjectStore,
    head_tree: Option<&Hash>,
    worktree_root: &Path,
    index: Option<&Index>,
) -> Result<Vec<StatusEntry>, DiffError>
Expand description

Compare HEAD ↔ index and index ↔ worktree, returning a list of StatusEntry grouped by staging state.

Pre-#102 this function diffed only HEAD↔worktree and annotated each entry with index-state. That hid one hazard: a path staged to the index whose worktree was later reverted to match HEAD would diff to nothing — but mkit commit (which signs HEAD↔ index post-#102) would still commit the staged content. The staged change was invisible to mkit status.

New shape:

  • Staged — path differs between HEAD and the index-built tree (the change is what mkit commit will sign).
  • Unstaged — path differs between the index-built tree and the worktree (changes the user has not yet mkit add-ed).
  • When the same path appears in both legs (e.g. staged v2, then worktree edited to v3), one entry is emitted per leg so callers render both sections — matching git’s two-section layout. The PartiallyStaged enum variant is retained for back-compat but no longer produced by this function.

When index is None, falls back to the legacy HEAD↔worktree diff and labels every entry Unstaged — used by callers that haven’t initialized a staging index yet.

§Errors

Propagates WorktreeError (I/O, symlink validation, chunker limit) and StoreError (missing or corrupt objects).