mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-15 01:51:46 +04:00
fix uninstall without -t to remove all pre-commit managed hooks
Previously, `pre-commit uninstall` without `-t` only removed hooks listed in `default_install_hook_types` from the config. This meant hooks installed with e.g. `-t pre-push` would not be removed unless `-t pre-push` was explicitly passed to uninstall. Now, when `-t` is not specified, uninstall scans all known hook types and removes any that are managed by pre-commit (via `is_our_script`). Fixes #364 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
8416413a0e
commit
16f7c46de5
2 changed files with 29 additions and 1 deletions
|
|
@ -1102,3 +1102,26 @@ def test_install_uninstall_default_hook_types(in_git_dir, store):
|
|||
assert not uninstall(C.CONFIG_FILE, hook_types=None)
|
||||
assert not in_git_dir.join('.git/hooks/pre-commit').exists()
|
||||
assert not in_git_dir.join('.git/hooks/pre-push').exists()
|
||||
|
||||
|
||||
def test_uninstall_without_t_removes_all_hooks(in_git_dir, store):
|
||||
install(C.CONFIG_FILE, store, hook_types=['pre-commit'])
|
||||
install(C.CONFIG_FILE, store, hook_types=['pre-push'])
|
||||
assert in_git_dir.join('.git/hooks/pre-commit').exists()
|
||||
assert in_git_dir.join('.git/hooks/pre-push').exists()
|
||||
|
||||
assert not uninstall(C.CONFIG_FILE, hook_types=None)
|
||||
assert not in_git_dir.join('.git/hooks/pre-commit').exists()
|
||||
assert not in_git_dir.join('.git/hooks/pre-push').exists()
|
||||
|
||||
|
||||
def test_uninstall_without_t_ignores_non_precommit_hooks(in_git_dir, store):
|
||||
install(C.CONFIG_FILE, store, hook_types=['pre-commit'])
|
||||
# write a non-pre-commit hook
|
||||
in_git_dir.join('.git/hooks/pre-push').write('#!/bin/sh\necho custom\n')
|
||||
assert in_git_dir.join('.git/hooks/pre-push').exists()
|
||||
|
||||
assert not uninstall(C.CONFIG_FILE, hook_types=None)
|
||||
assert not in_git_dir.join('.git/hooks/pre-commit').exists()
|
||||
# non-pre-commit hook should be preserved
|
||||
assert in_git_dir.join('.git/hooks/pre-push').exists()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue