Skip to main content

revision

Function revision 

Source
pub fn revision(root: &Path) -> Result<EconomicsRevision, String>
Expand description

The revision evidence is recorded at: HEAD, and whether the working tree differs from it anywhere outside the evidence directory. The records a suite writes are changes to the working tree too, and a measurement must not call its own output a dirty tree.

use majordomus_cli::economics::{revision, DIR};
let dir = tempfile::tempdir().unwrap();
git(&["init", "-q"]);
assert!(revision(dir.path()).is_err(), "no commit yet, so no HEAD to record against");
std::fs::write(dir.path().join("a.txt"), "one").unwrap();
git(&["add", "-A"]);
git(&["-c", "user.name=t", "-c", "user.email=t@example.com", "-c", "commit.gpgsign=false",
    "commit", "-qm", "one"]);
let clean = revision(dir.path()).unwrap();
assert_eq!((clean.commit.as_str(), clean.dirty), (git(&["rev-parse", "HEAD"]).trim(), false));

std::fs::create_dir_all(dir.path().join(DIR).join("runs")).unwrap();
std::fs::write(dir.path().join(DIR).join("runs/r1.json"), "{}").unwrap();
assert!(!revision(dir.path()).unwrap().dirty, "its own records do not dirty the tree");
std::fs::write(dir.path().join("a.txt"), "two").unwrap();
assert!(revision(dir.path()).unwrap().dirty);