Files
tetra-bluestation/contrib/pre-commit-hook/pre-commit
2026-02-22 19:48:58 +01:00

16 lines
624 B
Bash

#!/usr/bin/env bash
# This script has some limitations. Most notably, it checks the files on-disk, which is a problem
# if a file was edited, added and then re-edited. The added (and thus to be committed) file is
# different from the on-disk file. Furthermore, small differences between cargo ftm and rustfmt may exist.
# As this is just a helpful tool, we can accept those limitations.
set -euo pipefail
ROOT="$(git rev-parse --show-toplevel)"
CFG="$ROOT/rustfmt.toml"
git diff --cached --name-only -z --diff-filter=ACMR -- '*.rs' \
| xargs -0 -r rustfmt --config-path "$CFG" --check
echo "rustfmt check successful"