1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2026-01-19 03:31:09 +00:00
alejandra/pre-commit.sh
David Arnold 0e1e0f52db
fixup: re-add cargo & treefmt
- these where under the devshell commands section and fell through
2022-01-30 19:45:15 -05:00

23 lines
553 B
Bash

#!/usr/bin/env bash
if git rev-parse --verify HEAD > /dev/null 2>&1; then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=$(${git}/bin/git hash-object -t tree /dev/null)
fi
diff="git diff-index --name-only --cached $against --diff-filter d"
all_files=($($diff))
# Format the entire tree.
treefmt
# check editorconfig
editorconfig-checker -- "${all_files[@]}"
if [[ $? != '0' ]]; then
printf "%b\n" \
"\nCode is not aligned with .editorconfig" \
"Review the output and commit your fixes" >&2
exit 1
fi