anvilsign in

collin/anvil

1#!/bin/sh
2# Pre-commit: the toolchain-pin check, rustfmt (nightly, for the unstable
3# options in rustfmt.toml), cargo-sort-derives, and clippy.
4# Wired up via `git config core.hooksPath .githooks`.
5set -e
6
7# rust-toolchain.toml is the one place the Rust version is set, but Cargo's
8# `rust-version` floor is a separate key it cannot derive. Rather than let the
9# two drift silently, check that the pin satisfies the floor.
10PIN=$(sed -n 's/^[[:space:]]*channel[[:space:]]*=[[:space:]]*"\(.*\)".*/\1/p' rust-toolchain.toml)
11MSRV=$(sed -n 's/^[[:space:]]*rust-version[[:space:]]*=[[:space:]]*"\(.*\)".*/\1/p' Cargo.toml)
12case "$PIN" in
13 "$MSRV" | "$MSRV".*) ;;
14 *)
15 echo "pre-commit: rust-toolchain.toml pins $PIN but Cargo.toml rust-version is $MSRV." >&2
16 echo " Update the floor to match the pin." >&2
17 exit 1
18 ;;
19esac
20
21if ! cargo +nightly fmt --all -- --check >/dev/null 2>&1; then
22 cargo +nightly fmt --all
23 echo "pre-commit: rustfmt reformatted files — review, re-stage, and commit again." >&2
24 git diff --name-only -- '*.rs' >&2
25 exit 1
26fi
27
28if ! cargo sort-derives --check >/dev/null 2>&1; then
29 cargo sort-derives
30 echo "pre-commit: cargo sort-derives reordered derives — review, re-stage, and commit again." >&2
31 git diff --name-only -- '*.rs' >&2
32 exit 1
33fi
34
35cargo clippy --workspace --all-targets -- -D warnings