pub fn parse(report: &str) -> Option<GitWorkingTree>Expand description
Parse a git status --porcelain=v2 --branch -z report.
Records are NUL-separated. A rename record (2 ) carries two NUL-separated paths, so
the parser consumes one extra record after it; a parser that does not is silently one
record out of step for the rest of the report, which is the classic way this format is
got wrong.
use majordomus_cli::environment::vcs::parse;
// One record per entry, joined by the NUL the report separates them with.
let report = [
"# branch.oid abc123",
"# branch.head master",
"# branch.upstream origin/master",
"# branch.ab +2 -1",
"1 .M N... 100644 100644 100644 aaa bbb src/a.rs",
"1 M. N... 100644 100644 100644 ccc ddd src/b.rs",
"? notes.txt",
].join("\0");
let tree = parse(&report).expect("a branch header");
assert_eq!(tree.branch.as_deref(), Some("master"));
assert_eq!(tree.upstream.as_deref(), Some("origin/master"));
assert_eq!((tree.ahead, tree.behind), (Some(2), Some(1)));
assert_eq!((tree.staged, tree.modified, tree.untracked), (1, 1, 1));
assert!(!tree.clean);