Skip to main content

aged_dirty_state

Function aged_dirty_state 

Source
pub fn aged_dirty_state(
    worktree: &Path,
) -> Result<(DirtyState, Option<SystemTime>)>
Expand description

Uncommitted work in a work tree, counted as dirty_state counts it, with the moment of its oldest change: the earliest modification time among the paths git status names. A changed path that no longer exists on disk — a deletion — has no time of its own, and the index file’s modification time stands in for it, as it does for a work tree whose paths cannot be read at all. None only when neither can be read.

The status is the one dirty_state takes, under GIT_OPTIONAL_LOCKS=0, so measuring writes nothing: not the index, not a lock, not a stat cache.

use majordomus_cli::worktree::state::aged_dirty_state;
let repo = tempfile::tempdir().unwrap();
let init = std::process::Command::new("git")
    .args(["init", "-q"])
    .current_dir(repo.path())
    .status()
    .unwrap();
assert!(init.success());
let (clean, none) = aged_dirty_state(repo.path()).unwrap();
assert!(clean.clean && none.is_none(), "a clean work tree has no oldest change");
std::fs::write(repo.path().join("new.txt"), "work").unwrap();
let (dirty, oldest) = aged_dirty_state(repo.path()).unwrap();
assert_eq!(dirty.untracked, 1);
assert!(oldest.is_some(), "the file's own time is the change's");