ref: move devshell module here to devos
again
This commit is contained in:
parent
62f9d95259
commit
33fb25e011
8 changed files with 240 additions and 62 deletions
shell/hooks
4
shell/hooks/default.nix
Normal file
4
shell/hooks/default.nix
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
enable = true;
|
||||
pre-commit.text = builtins.readFile ./pre-commit.sh;
|
||||
}
|
29
shell/hooks/pre-commit.sh
Executable file
29
shell/hooks/pre-commit.sh
Executable file
|
@ -0,0 +1,29 @@
|
|||
#!/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.
|
||||
if [[ -n "${nix_files[@]}" ]]; then
|
||||
nixpkgs-fmt "${nix_files[@]}" \
|
||||
&& git add "${nix_files[@]}"
|
||||
fi
|
||||
|
||||
# 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
|
Loading…
Add table
Add a link
Reference in a new issue