2021-07-08 00:31:12 +00:00
|
|
|
#!/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"
|
|
|
|
|
2022-04-09 13:22:37 +00:00
|
|
|
mapfile -t nix_files < <($diff -- '*.nix')
|
|
|
|
mapfile -t all_files < <($diff)
|
2021-07-08 00:31:12 +00:00
|
|
|
|
|
|
|
# Format staged nix files.
|
|
|
|
if [[ -n "${nix_files[@]}" ]]; then
|
|
|
|
nixpkgs-fmt "${nix_files[@]}" \
|
|
|
|
&& git add "${nix_files[@]}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# check editorconfig
|
2022-04-09 13:42:36 +00:00
|
|
|
if ! editorconfig-checker -- "${all_files[@]}"; then
|
2021-07-08 00:31:12 +00:00
|
|
|
printf "%b\n" \
|
|
|
|
"\nCode is not aligned with .editorconfig" \
|
|
|
|
"Review the output and commit your fixes" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|