Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

post-checkout hooks do not run on new worktrees when .pre-commit-config.yaml is not committed #545

Open
eval-on-point opened this issue Jan 9, 2025 · 0 comments

Comments

@eval-on-point
Copy link

eval-on-point commented Jan 9, 2025

Given the following flake.nix:

{
  inputs.pre-commit-hooks.url = "github:cachix/git-hooks.nix";

  outputs =
    { self, nixpkgs, ... }@inputs:
    let
      supportedSystems = [
        "x86_64-linux"
        "aarch64-linux"
        "x86_64-darwin"
        "aarch64-darwin"
      ];

      forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
    in
    {
      checks = forAllSystems (system: {
        pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run {
          src = ./.;
          hooks = {
            post-checkout = {
              enable = true;
              entry = "echo success!";
              always_run = true;
              stages = [ "post-checkout" ];
            };
          };
        };
      });

      devShells = forAllSystems (system: {
        default = nixpkgs.legacyPackages.${system}.mkShell {
          inherit (self.checks.${system}.pre-commit-check) shellHook;
          buildInputs = self.checks.${system}.pre-commit-check.enabledPackages;
        };
      });
    };
}

The post-checkout hook does not run if .pre-commit.yaml is not in the repository:

$ nix develop
...
pre-commit installed at .git/hooks/post-checkout

$ git worktree add ../test
Preparing worktree (new branch 'test')
warning: asked to inherit tracking from 'main', but no remote is set
HEAD is now at b67e139 init
No .pre-commit-config.yaml file was found
- To temporarily silence this, run `PRE_COMMIT_ALLOW_NO_CONFIG=1 git ...`
- To permanently silence this, install pre-commit with the --allow-missing-config option
- To uninstall pre-commit run `pre-commit uninstall`

I believe that either #494 or #496 would create configuration options to fix this by using an absolute path for the .pre-commit-config.yaml.

@eval-on-point eval-on-point changed the title post-checkout hooks do not run post-checkout hooks do not run on new worktrees when .pre-commit-config.yaml is not committed Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant