Files
2026-10-18 15:22:02 -05:00

34 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# Row 125 r3: write the manifest of the 38 paths from wt3, cut build.patch.r3 against BASE3 with a scratch index,
# then prove it by applying it to BASE3 in a second scratch index and comparing every manifest path's blob.
set -euo pipefail
R=$HOME/dewey-scratch/r125; cd "$R/wt3"
BASE3=$(git rev-parse "${1:?r3 base sha}") M=$R/candidate-manifest.r3.sha256
[ "$(git rev-parse HEAD)" = "$BASE3" ] || { echo "abort: wt3 HEAD is not the base"; exit 2; }
[ -z "$(git diff --name-only --diff-filter=U)" ] || { echo "abort: unmerged paths"; exit 2; }
if grep -lE '^(<<<<<<<|>>>>>>>|=======$)' $(cat "$R/candidate-paths.r2.txt") 2>/dev/null; then echo "abort: conflict markers"; exit 2; fi
mapfile -t P < "$R/candidate-paths.r2.txt"
[ "${#P[@]}" -eq 38 ] || { echo "abort: ${#P[@]} paths"; exit 2; }
sha256sum -- "${P[@]}" > "$M"
I1=$R/tmp-index-cut3 I2=$R/tmp-index-check3; rm -f "$I1" "$I2"
GIT_INDEX_FILE=$I1 git read-tree "$BASE3"
GIT_INDEX_FILE=$I1 git add -- "${P[@]}"
GIT_INDEX_FILE=$I1 git diff --cached --binary "$BASE3" > "$R/build.patch.r3"
changed=$(GIT_INDEX_FILE=$I1 git diff --cached --name-only "$BASE3" | wc -l)
GIT_INDEX_FILE=$I2 git read-tree "$BASE3"
GIT_INDEX_FILE=$I2 git apply --cached "$R/build.patch.r3"
bad=0
for p in "${P[@]}"; do
want=$(awk -v p="$p" '$2 == p {print $1}' "$M")
got=$(GIT_INDEX_FILE=$I2 git cat-file -p ":$p" | sha256sum | cut -d' ' -f1)
[ "$want" = "$got" ] || { echo "MISMATCH $p"; bad=1; }
done
rm -f "$I1" "$I2"
[ $bad -eq 0 ] || exit 3
# Every path outside the 38 must be untouched against BASE3 (node_modules is the only untracked entry).
extra=$(git status --porcelain --untracked-files=all | awk '{print $2}' | grep -vxF -f "$R/candidate-paths.r2.txt" | grep -vx node_modules || true)
[ -z "$extra" ] || { echo "abort: paths outside the manifest changed: $extra"; exit 2; }
echo "paths in patch: $changed; all 38 blobs match after apply to $BASE3"
echo "build.patch.r3 $(sha256sum < "$R/build.patch.r3" | cut -d' ' -f1)"
echo "manifest r3 $(sha256sum < "$M" | cut -d' ' -f1)"