set -euo pipefail
if [[ "${SKIP:-}" == "1" ]]; then
echo "SKIP=1 detected — skipping pre-push checks."
exit 0
fi
echo "Preparing workspace for pre-push checks..."
STASHED=0
if ! git diff --quiet || ! git diff --cached --quiet; then
echo "Uncommitted changes detected — stashing..."
git stash push -u -k -q
STASHED=1
fi
cleanup() {
if [[ "$STASHED" -eq 1 ]]; then
echo "Restoring stashed changes..."
git stash pop -q || true
fi
}
trap cleanup EXIT
echo "Running pre-push checks..."
echo "1. cargo fmt --check"
cargo fmt --all -- --check
echo "2. cargo clippy"
cargo clippy --all-targets --all-features -- -D warnings
echo "3. cargo test"
cargo test --all-features --all-targets
echo "All checks passed."