set -euo pipefail
base="${1:-origin/main}"
root="$(git rev-parse --show-toplevel)"
cd "$root"
if [ -n "$(git status --porcelain)" ]; then
echo "mutants-diff: commit or stash your changes first; only committed changes are diffed" >&2
exit 1
fi
case "$base" in
origin/*) git fetch --quiet origin "${base#origin/}" ;;
esac
out="$root/target/mutants-diff"
mkdir -p "$out" "$root/target/mutants-home"
git diff "$base...HEAD" > "$out/pr.diff"
rustup_home="${RUSTUP_HOME:-$HOME/.rustup}"
cargo_home="${CARGO_HOME:-$HOME/.cargo}"
RUSTUP_HOME="$rustup_home" CARGO_HOME="$cargo_home" HOME="$root/target/mutants-home" \
"${CARGO:-cargo}" mutants --in-diff "$out/pr.diff" --test-tool nextest \
--no-shuffle -j "${MUTANTS_JOBS:-4}"