From 4ea20a18a5dcc7ce5e8111edd433250b04bb6164 Mon Sep 17 00:00:00 2001 From: Greedquest <25348920+Greedquest@users.noreply.github.com> Date: Mon, 24 Jan 2022 17:28:54 +0000 Subject: [PATCH] Update install_uninstall.py Slightly modify the output message to indicate whether a new hook file was created --- pre_commit/commands/install_uninstall.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pre_commit/commands/install_uninstall.py b/pre_commit/commands/install_uninstall.py index cb2aaa5b..53784695 100644 --- a/pre_commit/commands/install_uninstall.py +++ b/pre_commit/commands/install_uninstall.py @@ -61,8 +61,12 @@ def _install_hook_script( os.makedirs(os.path.dirname(hook_path), exist_ok=True) # 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): - shutil.move(hook_path, legacy_path) + our_script_was_already_installed = False + if os.path.lexists(hook_path): + if is_our_script(hook_path): + our_script_was_already_installed = True + else: + shutil.move(hook_path, legacy_path) # If we specify overwrite, we simply delete the legacy file if overwrite and os.path.exists(legacy_path): @@ -97,7 +101,10 @@ def _install_hook_script( hook_file.write(TEMPLATE_END + after) make_executable(hook_path) - output.write_line(f'pre-commit installed at {hook_path}') + if our_script_was_already_installed: + output.write_line(f'pre-commit already installed at {hook_path}') + else: + output.write_line(f'pre-commit installed at {hook_path}') def install(