There was an error while loading. Please reload this page.
2 parents b830026 + af2c6de commit 09e64e8Copy full SHA for 09e64e8
2 files changed
pre_commit/commands/install_uninstall.py
@@ -5,6 +5,7 @@
5
import itertools
6
import logging
7
import os.path
8
+import shutil
9
import sys
10
11
from pre_commit import git
@@ -84,7 +85,7 @@ def install(
84
85
86
# If we have an existing hook, move it to pre-commit.legacy
87
if os.path.lexists(hook_path) and not is_our_script(hook_path):
- os.rename(hook_path, legacy_path)
88
+ shutil.move(hook_path, legacy_path)
89
90
# If we specify overwrite, we simply delete the legacy file
91
if overwrite and os.path.exists(legacy_path):
tests/commands/install_uninstall_test.py
@@ -325,6 +325,16 @@ def test_install_existing_hooks_no_overwrite(tempdir_factory, store):
325
assert NORMAL_PRE_COMMIT_RUN.match(output[len('legacy hook\n'):])
326
327
328
+def test_legacy_overwriting_legacy_hook(tempdir_factory, store):
329
+ path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
330
+ with cwd(path):
331
+ _write_legacy_hook(path)
332
+ assert install(C.CONFIG_FILE, store) == 0
333
334
+ # this previously crashed on windows. See #1010
335
336
+
337
338
def test_install_existing_hook_no_overwrite_idempotent(tempdir_factory, store):
339
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
340
with cwd(path):
0 commit comments