Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0cde0fd

Browse files
committed
Uninstall restores hooks.
1 parent f4d16b9 commit 0cde0fd

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

pre_commit/commands/install_uninstall.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,9 @@ def uninstall(runner):
6161
if os.path.exists(runner.pre_commit_path):
6262
os.remove(runner.pre_commit_path)
6363
print('pre-commit uninstalled')
64+
65+
if os.path.exists(runner.pre_commit_legacy_path):
66+
os.rename(runner.pre_commit_legacy_path, runner.pre_commit_path)
67+
print('Restored previous hooks to {0}'.format(runner.pre_commit_path))
68+
6469
return 0

tests/commands/install_uninstall_test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,23 @@ def test_install_overwrite(tmpdir_factory):
256256
ret, output = _get_commit_output(tmpdir_factory)
257257
assert ret == 0
258258
assert NORMAL_PRE_COMMIT_RUN.match(output)
259+
260+
261+
def test_uninstall_restores_legacy_hooks(tmpdir_factory):
262+
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
263+
with local.cwd(path):
264+
runner = Runner(path)
265+
266+
# Write out an "old" hook
267+
with io.open(runner.pre_commit_path, 'w') as hook_file:
268+
hook_file.write('#!/usr/bin/env bash\necho "legacy hook"\n')
269+
make_executable(runner.pre_commit_path)
270+
271+
# Now install and uninstall pre-commit
272+
assert install(runner) == 0
273+
assert uninstall(runner) == 0
274+
275+
# Make sure we installed the "old" hook correctly
276+
ret, output = _get_commit_output(tmpdir_factory, touch_file='baz')
277+
assert ret == 0
278+
assert EXISTING_COMMIT_RUN.match(output)

0 commit comments

Comments
 (0)