mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-20 01:24:42 +04:00
Combine install and uninstall.
This commit is contained in:
parent
ac735e85e2
commit
f4d16b9cdc
5 changed files with 31 additions and 44 deletions
|
|
@ -54,3 +54,11 @@ def install(runner, overwrite=False):
|
||||||
|
|
||||||
print('pre-commit installed at {0}'.format(runner.pre_commit_path))
|
print('pre-commit installed at {0}'.format(runner.pre_commit_path))
|
||||||
return 0
|
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
|
||||||
|
|
@ -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
|
|
||||||
|
|
@ -6,9 +6,9 @@ import pkg_resources
|
||||||
from pre_commit import color
|
from pre_commit import color
|
||||||
from pre_commit.commands.autoupdate import autoupdate
|
from pre_commit.commands.autoupdate import autoupdate
|
||||||
from pre_commit.commands.clean import clean
|
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.run import run
|
||||||
from pre_commit.commands.uninstall import uninstall
|
|
||||||
from pre_commit.runner import Runner
|
from pre_commit.runner import Runner
|
||||||
from pre_commit.util import entry
|
from pre_commit.util import entry
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,10 @@ import subprocess
|
||||||
import stat
|
import stat
|
||||||
from plumbum import local
|
from plumbum import local
|
||||||
|
|
||||||
from pre_commit.commands.install import install
|
from pre_commit.commands.install_uninstall import install
|
||||||
from pre_commit.commands.install import is_our_pre_commit
|
from pre_commit.commands.install_uninstall import is_our_pre_commit
|
||||||
from pre_commit.commands.install import make_executable
|
from pre_commit.commands.install_uninstall import make_executable
|
||||||
|
from pre_commit.commands.install_uninstall import uninstall
|
||||||
from pre_commit.runner import Runner
|
from pre_commit.runner import Runner
|
||||||
from testing.fixtures import git_dir
|
from testing.fixtures import git_dir
|
||||||
from testing.fixtures import make_consuming_repo
|
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)
|
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'):
|
def _get_commit_output(tmpdir_factory, touch_file='foo'):
|
||||||
local['touch'](touch_file)
|
local['touch'](touch_file)
|
||||||
local['git']('add', touch_file)
|
local['git']('add', touch_file)
|
||||||
|
|
@ -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)
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue