mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Separate store from runner
This commit is contained in:
parent
6d683a5fac
commit
c01ffc83f8
15 changed files with 228 additions and 347 deletions
|
|
@ -7,6 +7,7 @@ import os.path
|
|||
import sys
|
||||
|
||||
from pre_commit import output
|
||||
from pre_commit.repository import repositories
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import make_executable
|
||||
from pre_commit.util import mkdirp
|
||||
|
|
@ -36,7 +37,7 @@ def is_our_script(filename):
|
|||
|
||||
|
||||
def install(
|
||||
runner, overwrite=False, hooks=False, hook_type='pre-commit',
|
||||
runner, store, overwrite=False, hooks=False, hook_type='pre-commit',
|
||||
skip_on_missing_conf=False,
|
||||
):
|
||||
"""Install the pre-commit hooks."""
|
||||
|
|
@ -89,13 +90,13 @@ def install(
|
|||
|
||||
# If they requested we install all of the hooks, do so.
|
||||
if hooks:
|
||||
install_hooks(runner)
|
||||
install_hooks(runner, store)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def install_hooks(runner):
|
||||
for repository in runner.repositories:
|
||||
def install_hooks(runner, store):
|
||||
for repository in repositories(runner.config, store):
|
||||
repository.require_installed()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ from pre_commit import color
|
|||
from pre_commit import git
|
||||
from pre_commit import output
|
||||
from pre_commit.output import get_hook_message
|
||||
from pre_commit.repository import repositories
|
||||
from pre_commit.staged_files_only import staged_files_only
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import memoize_by_cwd
|
||||
|
|
@ -223,7 +224,7 @@ def _has_unstaged_config(runner):
|
|||
return retcode == 1
|
||||
|
||||
|
||||
def run(runner, args, environ=os.environ):
|
||||
def run(runner, store, args, environ=os.environ):
|
||||
no_stash = args.all_files or bool(args.files)
|
||||
|
||||
# Check if we have unresolved merge conflict files and fail fast.
|
||||
|
|
@ -248,11 +249,11 @@ def run(runner, args, environ=os.environ):
|
|||
if no_stash:
|
||||
ctx = noop_context()
|
||||
else:
|
||||
ctx = staged_files_only(runner.store.directory)
|
||||
ctx = staged_files_only(store.directory)
|
||||
|
||||
with ctx:
|
||||
repo_hooks = []
|
||||
for repo in runner.repositories:
|
||||
for repo in repositories(runner.config, store):
|
||||
for _, hook in repo.hooks:
|
||||
if (
|
||||
(not args.hook or hook['id'] == args.hook) and
|
||||
|
|
|
|||
|
|
@ -20,10 +20,11 @@ def try_repo(args):
|
|||
ref = args.ref or git.head_rev(args.repo)
|
||||
|
||||
with tmpdir() as tempdir:
|
||||
store = Store(tempdir)
|
||||
if args.hook:
|
||||
hooks = [{'id': args.hook}]
|
||||
else:
|
||||
repo_path = Store(tempdir).clone(args.repo, ref)
|
||||
repo_path = store.clone(args.repo, ref)
|
||||
manifest = load_manifest(os.path.join(repo_path, C.MANIFEST_FILE))
|
||||
manifest = sorted(manifest, key=lambda hook: hook['id'])
|
||||
hooks = [{'id': hook['id']} for hook in manifest]
|
||||
|
|
@ -42,5 +43,4 @@ def try_repo(args):
|
|||
output.write(config_s)
|
||||
output.write_line('=' * 79)
|
||||
|
||||
runner = Runner('.', config_filename, store_dir=tempdir)
|
||||
return run(runner, args)
|
||||
return run(Runner('.', config_filename), store, args)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue