mirror of
https://github.com/MidnightBlueLabs/tetra-bluestation.git
synced 2026-03-29 05:09:51 +00:00
Added pre-commit hook
This commit is contained in:
21
contrib/pre-commit-hook/install_pre_commit_hook.sh
Executable file
21
contrib/pre-commit-hook/install_pre_commit_hook.sh
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# This script installs the pre-commit hook, that checks whether staged files
|
||||
# are formatted according to rustfmt.toml
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
|
||||
|
||||
ROOT="$(git -C "$SCRIPT_DIR" rev-parse --show-toplevel 2>/dev/null)" || {
|
||||
echo "install.sh: not inside a git repository" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
SRC="$SCRIPT_DIR/pre-commit"
|
||||
DST="$ROOT/.git/hooks/pre-commit"
|
||||
|
||||
cp -f "$SRC" "$DST"
|
||||
chmod +x "$DST"
|
||||
|
||||
echo "Installed: $DST"
|
||||
15
contrib/pre-commit-hook/pre-commit
Normal file
15
contrib/pre-commit-hook/pre-commit
Normal file
@@ -0,0 +1,15 @@
|
||||
#!/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"
|
||||
Reference in New Issue
Block a user