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

Skip to content

Commit af2c6de

Browse files
committed
Fix double legacy install on windows
1 parent b830026 commit af2c6de

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

pre_commit/commands/install_uninstall.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import itertools
66
import logging
77
import os.path
8+
import shutil
89
import sys
910

1011
from pre_commit import git
@@ -84,7 +85,7 @@ def install(
8485

8586
# If we have an existing hook, move it to pre-commit.legacy
8687
if os.path.lexists(hook_path) and not is_our_script(hook_path):
87-
os.rename(hook_path, legacy_path)
88+
shutil.move(hook_path, legacy_path)
8889

8990
# If we specify overwrite, we simply delete the legacy file
9091
if overwrite and os.path.exists(legacy_path):

tests/commands/install_uninstall_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,16 @@ def test_install_existing_hooks_no_overwrite(tempdir_factory, store):
325325
assert NORMAL_PRE_COMMIT_RUN.match(output[len('legacy hook\n'):])
326326

327327

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+
_write_legacy_hook(path)
334+
# this previously crashed on windows. See #1010
335+
assert install(C.CONFIG_FILE, store) == 0
336+
337+
328338
def test_install_existing_hook_no_overwrite_idempotent(tempdir_factory, store):
329339
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
330340
with cwd(path):

0 commit comments

Comments
 (0)