From fc7cf6fcfe668b37781d46cea03461fc6e1c6f3e Mon Sep 17 00:00:00 2001 From: Victor Engmark Date: Thu, 10 Oct 2024 13:04:21 +1300 Subject: [PATCH] pre-commit: test meta hooks Closes #270805 by verifying that #251418 fixes the issue. --- pkgs/tools/misc/pre-commit/default.nix | 4 +-- pkgs/tools/misc/pre-commit/tests.nix | 45 ++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 pkgs/tools/misc/pre-commit/tests.nix diff --git a/pkgs/tools/misc/pre-commit/default.nix b/pkgs/tools/misc/pre-commit/default.nix index 22cd01055783f9..d332e175da062d 100644 --- a/pkgs/tools/misc/pre-commit/default.nix +++ b/pkgs/tools/misc/pre-commit/default.nix @@ -181,8 +181,8 @@ buildPythonApplication rec { "pre_commit" ]; - passthru.tests.version = testers.testVersion { - package = pre-commit; + passthru.tests = callPackage ./tests.nix { + inherit git pre-commit; }; meta = with lib; { diff --git a/pkgs/tools/misc/pre-commit/tests.nix b/pkgs/tools/misc/pre-commit/tests.nix new file mode 100644 index 00000000000000..a1b40bc2d8ccef --- /dev/null +++ b/pkgs/tools/misc/pre-commit/tests.nix @@ -0,0 +1,45 @@ +{ + git, + pre-commit, + runCommand, + testers, +}: +{ + check-meta-hooks = + runCommand "check-meta-hooks" + { + nativeBuildInputs = [ + git + pre-commit + ]; + } + '' + cd "$(mktemp --directory)" + export HOME="$PWD" + cat << 'EOF' > .pre-commit-config.yaml + repos: + - repo: local + hooks: + - id: echo + name: echo + entry: echo + files: \.yaml$ + language: system + - repo: meta + hooks: + - id: check-hooks-apply + - id: check-useless-excludes + - id: identity + EOF + git config --global user.email "you@example.com" + git config --global user.name "Your Name" + git init --initial-branch=main + git add . + pre-commit run --all-files + touch $out + ''; + + version = testers.testVersion { + package = pre-commit; + }; +}