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