Merge pull request 'make git-hooks opt-in' (#1453) from git-hooks into main
This commit is contained in:
10
devShell.nix
10
devShell.nix
@@ -1,4 +1,4 @@
|
|||||||
{ inputs, ... }:
|
{ ... }:
|
||||||
{
|
{
|
||||||
perSystem =
|
perSystem =
|
||||||
{
|
{
|
||||||
@@ -9,7 +9,6 @@
|
|||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
writers = pkgs.callPackage ./pkgs/builders/script-writers.nix { };
|
writers = pkgs.callPackage ./pkgs/builders/script-writers.nix { };
|
||||||
inherit (pkgs.callPackage inputs.git-hooks { }) lib;
|
|
||||||
|
|
||||||
ansiEscapes = {
|
ansiEscapes = {
|
||||||
reset = ''\033[0m'';
|
reset = ''\033[0m'';
|
||||||
@@ -22,11 +21,6 @@
|
|||||||
select-shell = writers.writePython3Bin "select-shell" {
|
select-shell = writers.writePython3Bin "select-shell" {
|
||||||
flakeIgnore = [ "E501" ];
|
flakeIgnore = [ "E501" ];
|
||||||
} ./pkgs/scripts/select-shell.py;
|
} ./pkgs/scripts/select-shell.py;
|
||||||
|
|
||||||
# run treefmt before each commit
|
|
||||||
install-pre-commit-hook =
|
|
||||||
with lib.git-hooks;
|
|
||||||
pre-commit (wrap.abort-on-change config.treefmt.build.wrapper);
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
devShells.default = pkgs.mkShell {
|
devShells.default = pkgs.mkShell {
|
||||||
@@ -41,8 +35,6 @@
|
|||||||
config.treefmt.build.wrapper
|
config.treefmt.build.wrapper
|
||||||
];
|
];
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
${install-pre-commit-hook}
|
|
||||||
|
|
||||||
echo -e "${ansiEscapes.green}switch to another dev-shell using: select-shell${ansiEscapes.reset}"
|
echo -e "${ansiEscapes.green}switch to another dev-shell using: select-shell${ansiEscapes.reset}"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|||||||
17
flake.lock
generated
17
flake.lock
generated
@@ -40,22 +40,6 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"git-hooks": {
|
|
||||||
"flake": false,
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1716413087,
|
|
||||||
"narHash": "sha256-nSTIB7JeJGBGsvtqlyfhUByh/isyK1nfOq2YMxUOFJQ=",
|
|
||||||
"owner": "fricklerhandwerk",
|
|
||||||
"repo": "git-hooks",
|
|
||||||
"rev": "99a78fcf7dc03ba7b1d5c00af109c1e28ced3490",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "fricklerhandwerk",
|
|
||||||
"repo": "git-hooks",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixlib": {
|
"nixlib": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1712450863,
|
"lastModified": 1712450863,
|
||||||
@@ -149,7 +133,6 @@
|
|||||||
"inputs": {
|
"inputs": {
|
||||||
"disko": "disko",
|
"disko": "disko",
|
||||||
"flake-parts": "flake-parts",
|
"flake-parts": "flake-parts",
|
||||||
"git-hooks": "git-hooks",
|
|
||||||
"nixos-generators": "nixos-generators",
|
"nixos-generators": "nixos-generators",
|
||||||
"nixos-images": "nixos-images",
|
"nixos-images": "nixos-images",
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": "nixpkgs",
|
||||||
|
|||||||
@@ -21,8 +21,6 @@
|
|||||||
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
|
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
|
||||||
treefmt-nix.url = "github:numtide/treefmt-nix";
|
treefmt-nix.url = "github:numtide/treefmt-nix";
|
||||||
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
|
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
git-hooks.url = "github:fricklerhandwerk/git-hooks";
|
|
||||||
git-hooks.flake = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs =
|
outputs =
|
||||||
|
|||||||
28
scripts/pre-commit
Executable file
28
scripts/pre-commit
Executable file
@@ -0,0 +1,28 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# To install:
|
||||||
|
# ln -sf ../../scripts/pre-commit .git/hooks/pre-commit
|
||||||
|
set -o errexit
|
||||||
|
set -o nounset
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
readarray staged < <(git diff --name-only --cached)
|
||||||
|
[[ ${#staged[@]} = 0 ]] && exit
|
||||||
|
unstash() {
|
||||||
|
local ret=$?
|
||||||
|
set +e
|
||||||
|
git stash pop -q
|
||||||
|
exit "$ret"
|
||||||
|
}
|
||||||
|
git stash push --quiet --keep-index --message "pre-commit"
|
||||||
|
trap unstash EXIT
|
||||||
|
nix fmt
|
||||||
|
{
|
||||||
|
changed=$(git diff --name-only --exit-code);
|
||||||
|
status=$?;
|
||||||
|
} || true
|
||||||
|
if [[ $status -ne 0 ]]; then
|
||||||
|
exec 1>&2
|
||||||
|
echo Files changed by pre-commit hook:
|
||||||
|
echo "$changed"
|
||||||
|
exit $status
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user