mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #1011 from pre-commit/multi_install_windows
Fix double legacy install on windows
This commit is contained in:
commit
09e64e8ff6
2 changed files with 12 additions and 1 deletions
|
|
@ -5,6 +5,7 @@ import io
|
|||
import itertools
|
||||
import logging
|
||||
import os.path
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
from pre_commit import git
|
||||
|
|
@ -84,7 +85,7 @@ def install(
|
|||
|
||||
# If we have an existing hook, move it to pre-commit.legacy
|
||||
if os.path.lexists(hook_path) and not is_our_script(hook_path):
|
||||
os.rename(hook_path, legacy_path)
|
||||
shutil.move(hook_path, legacy_path)
|
||||
|
||||
# If we specify overwrite, we simply delete the legacy file
|
||||
if overwrite and os.path.exists(legacy_path):
|
||||
|
|
|
|||
|
|
@ -325,6 +325,16 @@ def test_install_existing_hooks_no_overwrite(tempdir_factory, store):
|
|||
assert NORMAL_PRE_COMMIT_RUN.match(output[len('legacy hook\n'):])
|
||||
|
||||
|
||||
def test_legacy_overwriting_legacy_hook(tempdir_factory, store):
|
||||
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||
with cwd(path):
|
||||
_write_legacy_hook(path)
|
||||
assert install(C.CONFIG_FILE, store) == 0
|
||||
_write_legacy_hook(path)
|
||||
# this previously crashed on windows. See #1010
|
||||
assert install(C.CONFIG_FILE, store) == 0
|
||||
|
||||
|
||||
def test_install_existing_hook_no_overwrite_idempotent(tempdir_factory, store):
|
||||
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||
with cwd(path):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue