Unverified Commit 291e11d9 authored by Victor Engmark's avatar Victor Engmark
Browse files

pre-commit: fix import bug for built-in hooks



And add regression test.

Closes #270805.

Co-Authored-By: default avatarMatt Rixman <MatrixManAtYrService@users.noreply.github.com>
parent ae7c1f0f
Loading
Loading
Loading
Loading
+2 −8
Original line number Diff line number Diff line
@@ -107,12 +107,6 @@ buildPythonApplication rec {
    deactivate
  '';

  # Propagating dependencies leaks them through $PYTHONPATH which causes issues
  # when used in nix-shell.
  postFixup = ''
    rm $out/nix-support/propagated-build-inputs
  '';

  disabledTests = [
    # ERROR: The install method you used for conda--probably either `pip install conda`
    # or `easy_install conda`--is not compatible with using conda as an application.
@@ -182,8 +176,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; {
+45 −0
Original line number Diff line number Diff line
{
  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;
  };
}