mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #53 from pre-commit/pre_commit_clean
Implement the clean command.
This commit is contained in:
commit
b83b040ca4
3 changed files with 25 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ from __future__ import print_function
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
import shutil
|
||||||
import stat
|
import stat
|
||||||
from plumbum import local
|
from plumbum import local
|
||||||
|
|
||||||
|
|
@ -117,3 +118,10 @@ def autoupdate(runner):
|
||||||
)
|
)
|
||||||
|
|
||||||
return retv
|
return retv
|
||||||
|
|
||||||
|
|
||||||
|
def clean(runner):
|
||||||
|
if os.path.exists(runner.hooks_workspace_path):
|
||||||
|
shutil.rmtree(runner.hooks_workspace_path)
|
||||||
|
print('Cleaned {0}.'.format(runner.hooks_workspace_path))
|
||||||
|
return 0
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,8 @@ def run(argv):
|
||||||
|
|
||||||
subparsers.add_parser('uninstall', help='Uninstall the pre-commit script.')
|
subparsers.add_parser('uninstall', help='Uninstall the pre-commit script.')
|
||||||
|
|
||||||
|
subparsers.add_parser('clean', help='Clean out pre-commit files.')
|
||||||
|
|
||||||
subparsers.add_parser('autoupdate', help='Auto-update hooks config.')
|
subparsers.add_parser('autoupdate', help='Auto-update hooks config.')
|
||||||
|
|
||||||
run = subparsers.add_parser('run', help='Run hooks.')
|
run = subparsers.add_parser('run', help='Run hooks.')
|
||||||
|
|
@ -123,6 +125,8 @@ def run(argv):
|
||||||
return commands.install(runner)
|
return commands.install(runner)
|
||||||
elif args.command == 'uninstall':
|
elif args.command == 'uninstall':
|
||||||
return commands.uninstall(runner)
|
return commands.uninstall(runner)
|
||||||
|
elif args.command == 'clean':
|
||||||
|
return commands.clean(runner)
|
||||||
elif args.command == 'autoupdate':
|
elif args.command == 'autoupdate':
|
||||||
return commands.autoupdate(runner)
|
return commands.autoupdate(runner)
|
||||||
elif args.command == 'run':
|
elif args.command == 'run':
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ from pre_commit import git
|
||||||
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
|
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
|
||||||
from pre_commit.clientlib.validate_config import validate_config_extra
|
from pre_commit.clientlib.validate_config import validate_config_extra
|
||||||
from pre_commit.commands import autoupdate
|
from pre_commit.commands import autoupdate
|
||||||
|
from pre_commit.commands import clean
|
||||||
from pre_commit.commands import install
|
from pre_commit.commands import install
|
||||||
from pre_commit.commands import RepositoryCannotBeUpdatedError
|
from pre_commit.commands import RepositoryCannotBeUpdatedError
|
||||||
from pre_commit.commands import uninstall
|
from pre_commit.commands import uninstall
|
||||||
|
|
@ -163,3 +164,15 @@ def test_autoupdate_hook_disappearing_repo(hook_disappearing_repo):
|
||||||
after = open(C.CONFIG_FILE).read()
|
after = open(C.CONFIG_FILE).read()
|
||||||
assert ret == 1
|
assert ret == 1
|
||||||
assert before == after
|
assert before == after
|
||||||
|
|
||||||
|
|
||||||
|
def test_clean(empty_git_dir):
|
||||||
|
os.mkdir(C.HOOKS_WORKSPACE)
|
||||||
|
clean(Runner(empty_git_dir))
|
||||||
|
assert not os.path.exists(C.HOOKS_WORKSPACE)
|
||||||
|
|
||||||
|
|
||||||
|
def test_clean_empty(empty_git_dir):
|
||||||
|
assert not os.path.exists(C.HOOKS_WORKSPACE)
|
||||||
|
clean(Runner(empty_git_dir))
|
||||||
|
assert not os.path.exists(C.HOOKS_WORKSPACE)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue