git-hooks.nix icon indicating copy to clipboard operation
git-hooks.nix copied to clipboard

Make hook installation optional

Open roberth opened this issue 2 years ago • 5 comments

A highly opinionated workflow doesn't work for all projects, especially ones that already have a long history, notably NixOS/nix. Some people hate pre-commit with a passion.

These things should not be showstoppers.

To quote the docs:

Opting out, opting in

Users can enforce their own preference by setting NIX_PRE_COMMIT_HOOKS_INSTALL to 0 or 1 in their environment, e.g. in .profile or in home.sessionVariables for home-manager users.

Furthermore, project maintainers can set a default preference via the installByDefault option.

Finally, regardless of these settings, you may install the hooks manually by running nix-pre-commit-hooks-install in your shell. This does what it says, and the shell hook will detect that the hooks exist and keep them up to date.

roberth avatar Mar 17 '23 14:03 roberth

I'm confused why this is needed, can't you make the call to pre-commit run optional based on a boolean?

domenkozar avatar Apr 11 '23 00:04 domenkozar

I don't think run is responsible for installation.

The goal is to let a project choose not to install any hooks into .git by default, unless the devShell user has opted in. I think something might done at the project level, but it won't be quite as user friendly, as it doesn't standardize this installation logic.

roberth avatar Apr 11 '23 00:04 roberth

I've re-done it. This time it just (cleanly) refactors the existing logic, so that it can be called without installing the hooks into .git. Solved some tech debt along with that. We now have shellcheck on the script.

roberth avatar Apr 14 '23 15:04 roberth

@roberth I'd love to have this. Are you willing to refresh your PR?

phip1611 avatar Jan 12 '24 14:01 phip1611

Sorry for the mess, we revamed module structure in https://github.com/cachix/pre-commit-hooks.nix/pull/397, could you port these changes over?

domenkozar avatar Mar 19 '24 03:03 domenkozar

Closing as outdated

domenkozar avatar Jul 11 '24 20:07 domenkozar

Is the functionality request outdated or just the state of the PR?

Is there a replacement?

phip1611 avatar Jul 11 '24 20:07 phip1611

I think having enable option would make this a lot simpler, I'm happy to merge it if someone makes a PR.

domenkozar avatar Jul 12 '24 08:07 domenkozar