mirror of
https://github.com/divnix/digga.git
synced 2024-12-22 23:51:39 +03:00
♻️ env
Add pre-commit hook
This commit is contained in:
parent
6fc11c3e33
commit
ae42683ca1
@ -123,12 +123,14 @@
|
||||
collectHostsOnSystem
|
||||
;
|
||||
|
||||
# editorconfig-checker-disable
|
||||
# DEPRECATED - will be removed soon
|
||||
inherit
|
||||
(deprecated)
|
||||
# Place any deprecated lib functions here
|
||||
|
||||
;
|
||||
# editorconfig-checker-enable
|
||||
};
|
||||
|
||||
# a little extra service ...
|
||||
@ -148,6 +150,6 @@
|
||||
# system-space and pass sytem and input to each file
|
||||
jobs = polyfillOutput ./jobs;
|
||||
checks = polyfillOutput ./checks;
|
||||
devShell = polyfillOutput ./devShell.nix;
|
||||
devShell = polyfillOutput ./shell;
|
||||
};
|
||||
}
|
||||
|
@ -63,9 +63,11 @@
|
||||
};
|
||||
in
|
||||
devshell.mkShell {
|
||||
imports = [(devshell.extraModulesDir + "/git/hooks.nix")];
|
||||
name = "digga";
|
||||
packages = with pkgs; [
|
||||
fd
|
||||
editorconfig-checker
|
||||
treefmt
|
||||
alejandra
|
||||
nodePackages.prettier
|
||||
@ -108,4 +110,9 @@ in
|
||||
(docs {package = pkgs.mdbook;})
|
||||
(docs makeDocs)
|
||||
];
|
||||
|
||||
git.hooks = {
|
||||
enable = true;
|
||||
pre-commit.text = builtins.readFile ./pre-commit.sh;
|
||||
};
|
||||
}
|
28
shell/pre-commit.sh
Executable file
28
shell/pre-commit.sh
Executable file
@ -0,0 +1,28 @@
|
||||
#!/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 staged files.
|
||||
if ((${#all_files[@]} != 0)); then
|
||||
fmt "${all_files[@]}" &&
|
||||
git add "${all_files[@]}"
|
||||
fi
|
||||
|
||||
# check editorconfig
|
||||
if ((${#all_files[@]} != 0)); then
|
||||
if ! editorconfig-checker -- "${all_files[@]}"; then
|
||||
printf "%b\n" \
|
||||
"\nCode is not aligned with .editorconfig" \
|
||||
"Review the output and commit your fixes" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
Loading…
Reference in New Issue
Block a user