File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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\n echo "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 )
You can’t perform that action at this time.
0 commit comments