pub fn compare(
root: &Path,
evidence_commit: &str,
presented: &Presented,
) -> ComparisonExpand description
Compare one evidence commit with the presented revision. For the working tree the containing commit is HEAD (an unborn HEAD contains nothing anyone can name); for a presented commit it is that commit.
When git cannot place the evidence commit in the presented revision — either of the two
names no commit here — nothing is diffed and changed is None: the truth table reads
that as stale already, and a word that names no commit never reaches git diff.
use majordomus_cli::evidence::freshness::{compare, Presented};
use majordomus_cli::git::Containment;
use std::process::Command;
let dir = tempfile::tempdir().unwrap();
let git = |args: &[&str]| {
let out = Command::new("git").arg("-C").arg(dir.path()).args(args).output().unwrap();
String::from_utf8_lossy(&out.stdout).trim().to_string()
};
git(&["init", "-q"]);
git(&["config", "user.email", "t@example.com"]);
git(&["config", "user.name", "t"]);
git(&["commit", "-q", "--allow-empty", "-m", "one"]);
let e = git(&["rev-parse", "HEAD"]);
let c = compare(dir.path(), &e, &Presented::WorkingTree);
assert_eq!(c.containment, Containment::Contains);
assert_eq!(c.changed, Some(Default::default()));
let gone = compare(dir.path(), &"0".repeat(40), &Presented::WorkingTree);
assert_eq!(gone.containment, Containment::CommitUnknown);