Skip to main content

working_tree_excluding

Function working_tree_excluding 

Source
pub fn working_tree_excluding(
    root: &Path,
    ignore: &[&str],
    outputs: &[&str],
) -> String
Expand description

clean, dirty or unknown, as working_tree_ignoring decides it, except that an untracked path equal to one of outputs, or under one of them, is not a change either. An output never hides a tracked change.

This is the one tree measurement: a run’s stamp and the presented tree both go through it. A run writes its own report and build products into the checkout; those are not a change to what it tested, but only while they are untracked. A tracked file under an output is still a change, so an output cannot be used to make a modified checkout read clean. Outputs are compared by path segment (dist covers dist/out.bin, never distx/y), after a leading ./ and a trailing / are removed; no pathspec is ever built from them.

use majordomus_cli::git::working_tree_excluding;
use std::process::Command;

let dir = tempfile::tempdir().unwrap();
let git = |args: &[&str]| {
    Command::new("git").arg("-C").arg(dir.path()).args(args).output().unwrap()
};
git(&["init", "-q"]);
git(&["config", "user.email", "t@example.com"]);
git(&["config", "user.name", "t"]);
std::fs::write(dir.path().join("a.md"), "a").unwrap();
git(&["add", "-A"]);
git(&["commit", "-qm", "init"]);

std::fs::create_dir(dir.path().join("dist")).unwrap();
std::fs::write(dir.path().join("dist/out.bin"), "x").unwrap();
assert_eq!(working_tree_excluding(dir.path(), &[], &["dist"]), "clean");
assert_eq!(working_tree_excluding(dir.path(), &[], &[]), "dirty");

// an output never hides a tracked change
std::fs::write(dir.path().join("a.md"), "b").unwrap();
assert_eq!(working_tree_excluding(dir.path(), &[], &["dist", "a.md"]), "dirty");