Add pre-commit hook script to run nixfmt check.
This commit is contained in:
parent
b7f2e439c8
commit
1f63817684
1 changed files with 22 additions and 0 deletions
22
hooks/pre-commit
Executable file
22
hooks/pre-commit
Executable file
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
printf "%s\n" "Running nixfmt pre-commit hook.";
|
||||
if ! which grep >/dev/null; then
|
||||
printf '%s\n' "ERR: grep not found.";
|
||||
exit 1;
|
||||
fi;
|
||||
|
||||
if ! which nixfmt >/dev/null; then
|
||||
printf '%s\n' "ERR: nixfmt not found.";
|
||||
exit 1;
|
||||
fi;
|
||||
|
||||
RESULT=0;
|
||||
for file in $(git diff --name-only --cached); do
|
||||
if grep -q "\.nix$" <<< "${file}"; then
|
||||
nixfmt -c <<< "$(git cat-file blob :"${file}")" 2> >(sed "s|<stdin>|${file}|");
|
||||
RESULT=$(( RESULT || $? ));
|
||||
fi;
|
||||
done;
|
||||
|
||||
exit ${RESULT};
|
Loading…
Reference in a new issue