Devenv.sh - How to avoid pre-commit?

I have just started with devenv.sh (and Nix) and I have something working. So far, so good.

Unfortunately, it appears that it always enables pre-commit-hooks which then forces various changes to my Git setup and breaks basic Git functionality.

I get the impression that it comes in through my inputs, i.e. I see it listed under “Inputs:” when running devenv info. Is there any way to delete from inputs? How should I go about removing pre-commit-hooks?

Disable those that break stuff for you.

Hi! Did you enable any commit hooks? Currently they aren’t automatically uninstalled, I should fix that.

I did not enable anything. :slight_smile:

As far as I can tell, the used library enables nixpkgs-fmt check by default. I had to disable it explicitely on my end, where I use alejandra.

Though I use pre-commit directly, without devenv.

No, I did not. I did not touch the pre-commit-hook functionality at all. Until I noticed it had been enabled.

My best workaround (that I am not happy with) is to set PRE_COMMIT_ALLOW_NO_CONFIG and to remove .pre-commit-config.yaml but that leaves an annoying warning: “.pre-commit-config.yaml config file not found. Skipping pre-commit.”.

(I am curious why .pre-commit-config.yaml is not recreated? I never created it but exiting and re-entering the directory does not recreate it. To be clear, I don’t want it recreated, I am just surprised that it’s not being recreated. :slight_smile: )

I will give that a try.

The best I have come up with so far is to have a minimal .pre-commit-config.yaml with just repos: []. It does not seem like I need to disable any pre-commit checks.

We already have quite a few dot files so I would prefer not to add to it. So, @domenkozar if you could make it so pre-commit-hooks is totally invisible unless explicitly enabled, that would be awesome. I think the issue you linked to is about that? For now, I will just go with the minimal .pre-commit-config.yaml.

I’ll look into the issue soon, thanks for raising this up.

Most likely you had a pre-commit hook at some point, which installed .git/hooks/pre-commit. That’s what this issue is about, removing it if pre-commit is disabled.

Ah, there is a .git/hooks/pre-commit but the timestamp is December 21st. So it was somehow installed very recently and not by me (or at least not by me directly).

And removing that .git/hooks/pre-commit fixes all my problems, apparently. It seems I no longer need the .pre-commit-config.yaml.

That’s right. The tricky bit to do this automatically is that you might want to manage pre-commit hooks outside of devenv, so we somehow need to know it was installed by us.

Yeah, that’s tricky indeed. Perhaps you could add a “special” comment in the devenv pre-commit hook to identify it. Still fairly fragile…

I was under the impression pre-commit-hooks.nix was already aware of that…

At least it was able to install itself in co-existence with lefthook and I had to manually fix that by myself when I moved over.