git-hooks.nix
git-hooks.nix copied to clipboard
bug: `pre-commit's script is installed in migration mode`
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.
What even is migration mode?
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
I do sometimes run pre-commit run --all-files directly from my cmd, could that be an issue?
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.
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 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.
If anyone encounters this, please save a copy of
.git/hooksbefore 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.
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'
@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.