From f4d16b9cdc74fb0043e43b7ade505261330fbef9 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Mon, 16 Jun 2014 17:44:48 -0700 Subject: [PATCH] Combine install and uninstall. --- .../{install.py => install_uninstall.py} | 8 ++++++ pre_commit/commands/uninstall.py | 13 ---------- pre_commit/main.py | 4 +-- ...tall_test.py => install_uninstall_test.py} | 24 ++++++++++++++--- tests/commands/uninstall_test.py | 26 ------------------- 5 files changed, 31 insertions(+), 44 deletions(-) rename pre_commit/commands/{install.py => install_uninstall.py} (88%) delete mode 100644 pre_commit/commands/uninstall.py rename tests/commands/{install_test.py => install_uninstall_test.py} (91%) delete mode 100644 tests/commands/uninstall_test.py diff --git a/pre_commit/commands/install.py b/pre_commit/commands/install_uninstall.py similarity index 88% rename from pre_commit/commands/install.py rename to pre_commit/commands/install_uninstall.py index 242d2e83..abc6c8ad 100644 --- a/pre_commit/commands/install.py +++ b/pre_commit/commands/install_uninstall.py @@ -54,3 +54,11 @@ def install(runner, overwrite=False): print('pre-commit installed at {0}'.format(runner.pre_commit_path)) return 0 + + +def uninstall(runner): + """Uninstall the pre-commit hooks.""" + if os.path.exists(runner.pre_commit_path): + os.remove(runner.pre_commit_path) + print('pre-commit uninstalled') + return 0 diff --git a/pre_commit/commands/uninstall.py b/pre_commit/commands/uninstall.py deleted file mode 100644 index 52e0dca3..00000000 --- a/pre_commit/commands/uninstall.py +++ /dev/null @@ -1,13 +0,0 @@ -from __future__ import print_function -from __future__ import unicode_literals - -import os -import os.path - - -def uninstall(runner): - """Uninstall the pre-commit hooks.""" - if os.path.exists(runner.pre_commit_path): - os.remove(runner.pre_commit_path) - print('pre-commit uninstalled') - return 0 diff --git a/pre_commit/main.py b/pre_commit/main.py index af8f2a13..eb678a90 100644 --- a/pre_commit/main.py +++ b/pre_commit/main.py @@ -6,9 +6,9 @@ import pkg_resources from pre_commit import color from pre_commit.commands.autoupdate import autoupdate from pre_commit.commands.clean import clean -from pre_commit.commands.install import install +from pre_commit.commands.install_uninstall import install +from pre_commit.commands.install_uninstall import uninstall from pre_commit.commands.run import run -from pre_commit.commands.uninstall import uninstall from pre_commit.runner import Runner from pre_commit.util import entry diff --git a/tests/commands/install_test.py b/tests/commands/install_uninstall_test.py similarity index 91% rename from tests/commands/install_test.py rename to tests/commands/install_uninstall_test.py index 44842774..bd0780ac 100644 --- a/tests/commands/install_test.py +++ b/tests/commands/install_uninstall_test.py @@ -10,9 +10,10 @@ import subprocess import stat from plumbum import local -from pre_commit.commands.install import install -from pre_commit.commands.install import is_our_pre_commit -from pre_commit.commands.install import make_executable +from pre_commit.commands.install_uninstall import install +from pre_commit.commands.install_uninstall import is_our_pre_commit +from pre_commit.commands.install_uninstall import make_executable +from pre_commit.commands.install_uninstall import uninstall from pre_commit.runner import Runner from testing.fixtures import git_dir from testing.fixtures import make_consuming_repo @@ -46,6 +47,23 @@ def test_install_pre_commit(tmpdir_factory): assert stat_result.st_mode & (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) +def test_uninstall_does_not_blow_up_when_not_there(tmpdir_factory): + path = git_dir(tmpdir_factory) + runner = Runner(path) + ret = uninstall(runner) + assert ret == 0 + + +def test_uninstall(tmpdir_factory): + path = git_dir(tmpdir_factory) + runner = Runner(path) + assert not os.path.exists(runner.pre_commit_path) + install(runner) + assert os.path.exists(runner.pre_commit_path) + uninstall(runner) + assert not os.path.exists(runner.pre_commit_path) + + def _get_commit_output(tmpdir_factory, touch_file='foo'): local['touch'](touch_file) local['git']('add', touch_file) diff --git a/tests/commands/uninstall_test.py b/tests/commands/uninstall_test.py deleted file mode 100644 index 9d5a38ed..00000000 --- a/tests/commands/uninstall_test.py +++ /dev/null @@ -1,26 +0,0 @@ -from __future__ import absolute_import -from __future__ import unicode_literals - -import os.path - -from pre_commit.runner import Runner -from pre_commit.commands.install import install -from pre_commit.commands.uninstall import uninstall -from testing.fixtures import git_dir - - -def test_uninstall_does_not_blow_up_when_not_there(tmpdir_factory): - path = git_dir(tmpdir_factory) - runner = Runner(path) - ret = uninstall(runner) - assert ret == 0 - - -def test_uninstall(tmpdir_factory): - path = git_dir(tmpdir_factory) - runner = Runner(path) - assert not os.path.exists(runner.pre_commit_path) - install(runner) - assert os.path.exists(runner.pre_commit_path) - uninstall(runner) - assert not os.path.exists(runner.pre_commit_path)