Skip to content

AutoActivation: Checking out old branches breaks pre-commit #2832

@tebriel

Description

@tebriel

Describe the bug

When using devenv activate (also direnv) if you have pre-commit hooks and check out an older (or newer) version of your devenv.lock the pre-commit fingerprint on the installed hook will change, which causes the pre-commit hooks to fail until repaired.

To reproduce

  • Turn on auto-activation (through devenv or direnv) on a repo with pre-commit hooks.
  • Check out an older branch/commit
  • Auto-activate will attempt to update the pre-commit hooks but will not error
  • Attempt to commit a file that needs to be evaluated by the hook
  • Error message:
bug: pre-commit's script is installed in migration mode
run `pre-commit install -f --hook-type pre-commit` to fix this.

Create gist here: https://gist.github.com/

Make sure to include full logs and what you expected to happen.
-->

Workaround

Run the command it tells you to:

nix-shell -p pre-commit --run 'pre-commit install -f --hook-type pre-commit'

You can resume committing (most of the time, sometimes it requires you to delete a file in the .git/hooks folder. It outputs what to do in this case, but I haven't figured out how to reproduce this to get the exact error message again. Something like "cowardly refusing to do....")

Version

devenv 2.1.0 (aarch64-darwin)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions