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

bug: `pre-commit's script is installed in migration mode`

Open joscha opened this issue 1 year ago • 9 comments

I randomly started getting:

bug: pre-commit's script is installed in migration mode
run `pre-commit install -f --hook-type commit-msg` to fix this

unsure where the issue is. I did find https://github.com/pre-commit/pre-commit/issues/1419 and commented there, however, it was locked by the project owner there unfortunately, suggesting we might be the culprit.

Any ideas?

git config --unset-all core.hooksPath
pre-commit install -f --hook-type commit-msg

fixed it, but I am unsure if I have now bypassed some of the logic from git-hooks.nix.

joscha avatar Oct 08 '24 11:10 joscha

What even is migration mode?

sandydoo avatar Oct 08 '24 11:10 sandydoo

What even is migration mode?

I think it refers to this: https://github.com/pre-commit/pre-commit.com/blob/main/sections/advanced.md#running-in-migration-mode

But I haven't done anything to the install other than updating my flake.lock

joscha avatar Oct 08 '24 12:10 joscha

I do sometimes run pre-commit run --all-files directly from my cmd, could that be an issue?

joscha avatar Oct 08 '24 12:10 joscha

I do sometimes run pre-commit run --all-files directly from my cmd, could that be an issue?

That's completely fine. We don't patch pre-commit, despite what the maintainers of pre-commit insist on saying...

It looks like they're searching for a hash in .git/hooks/<hook_stage>, and if they don't find it, they error out. We call pre-commit install internally, so I'm not really sure why this hash would be missing.

sandydoo avatar Oct 08 '24 12:10 sandydoo

If anyone encounters this, please save a copy of .git/hooks before trying to fix the error. The files in there would really help debug this issue.

sandydoo avatar Oct 08 '24 12:10 sandydoo

I do sometimes run pre-commit run --all-files directly from my cmd, could that be an issue?

That's completely fine. We don't patch pre-commit, despite what the maintainers of pre-commit insist on saying...

@asottile this may have been outdated information. Might be worth unlocking that issue, so at least the two issues get cross-referenced for others to find.

joscha avatar Oct 08 '24 13:10 joscha

If anyone encounters this, please save a copy of .git/hooks before trying to fix the error. The files in there would really help debug this issue.

I had that as an afterthought. I also didn't look at core.hooksPath either before blowing it away 🤦 . If/when it happens again I'll report here.

joscha avatar Oct 08 '24 13:10 joscha

I just got this error when performing a git push. As requested, a copy of .git/hooks is attached. The method mentioned by OP fixed it.

bug: pre-commit's script is installed in migration mode
run `pre-commit install -f --hook-type pre-push` to fix this

Please report this bug at https://github.com/pre-commit/pre-commit/issues
check-added-large-files..................................................Passed
trim-trailing-whitespace.................................................Passed
error: failed to push some refs to 'github.com:strykeforce/strykeforce.org.git'

hooks.tgz

jhh avatar Feb 25 '25 12:02 jhh

@jhh, thank you!

First, a bit of background on what I've figured out about this. If a hook exists, pre-commit will check whether it contains one of its hardcoded hashes/ids. If it doesn't, the hook file gets moved to .legacy and you get this error.

Now, what I thought we'd see here is a different hash in the legacy file, perhaps after switching to an older pre-commit version that isn't aware of the new hash. Instead, the .legacy and non-legacy hooks are identical.

So, that's a big 🤷 from me on this.

sandydoo avatar Feb 25 '25 14:02 sandydoo