Skip to content

prek uninstall without -t should remove all prek-managed hooks #1779

@Tiryoh

Description

@Tiryoh

Summary

prek uninstall without -t only removes the pre-commit hook, even if other prek-managed hooks (e.g. pre-push, commit-msg) exist in .git/hooks/. Users have to remember exactly which -t flags they used during install, or set default_install_hook_types in the config, to fully uninstall.

This is the same issue as pre-commit/pre-commit#364.

Note: This is specifically about the uninstall behavior, not about auto-detecting hook types during install (which was discussed in #1774 / #1224).

Reproduction

prek install -t pre-push
prek uninstall
# .git/hooks/pre-push still exists and is managed by prek

Expected behavior

prek uninstall without -t (and without default_install_hook_types in config) removes all prek-managed hooks found in the hooks directory.

prek already has is_our_script() to detect its own hooks, so scanning the hooks directory and removing only prek-managed ones is straightforward and safe.

Current behavior

get_hook_types() falls back to [pre-commit], so only the pre-commit hook is targeted for removal.

Proposed fix

Add a separate resolution path for uninstall: when no -t is given and no default_install_hook_types is configured, iterate over all known HookType variants in the hooks directory and remove those where is_our_script() returns true.

This keeps the current behavior when -t or default_install_hook_types is explicitly set.

I have a draft implementation on my fork: Tiryoh/prek@fix/uninstall-remove-all-managed-hooks.
If this direction looks good, I'm happy to open a PR as-is.

Willing to submit a PR?

  • Yes — I'm willing to open a PR to fix this.

Platform

Linux

Version

prek 0.3.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    ideaJust an idea

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions