pub fn listing_hash(listing: &str) -> StringExpand description
The hash mj_inputs_hash computes, reproduced.
The shell hashes each selected file, renders one <path> <sha256> line per file in
git’s own index order, and hashes that listing. Both halves matter: the order is git’s,
so two runs over one tree agree, and the listing carries the path, so moving a file
changes the hash even when its bytes do not.
A file git tracks and the working tree does not hold is skipped rather than failed, for
the same reason the shell skips it — shasum writes to stderr and xargs carries on —
so a deleted-but-tracked file makes the hash differ rather than making the answer an
error.
use majordomus_cli::capability::builtin::obligations::listing_hash;
// the listing is what is hashed, and it is one line per file, path first
assert_eq!(
listing_hash("a.txt e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n"),
listing_hash("a.txt e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n")
);
assert_ne!(listing_hash("a.txt 00\n"), listing_hash("b.txt 00\n"));