mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-19 09:04:41 +04:00
Remove noop_context
This commit is contained in:
parent
2a9893d0f0
commit
49cf490697
2 changed files with 9 additions and 13 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import argparse
|
import argparse
|
||||||
|
import contextlib
|
||||||
import functools
|
import functools
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
@ -27,7 +28,6 @@ from pre_commit.staged_files_only import staged_files_only
|
||||||
from pre_commit.store import Store
|
from pre_commit.store import Store
|
||||||
from pre_commit.util import cmd_output_b
|
from pre_commit.util import cmd_output_b
|
||||||
from pre_commit.util import EnvironT
|
from pre_commit.util import EnvironT
|
||||||
from pre_commit.util import noop_context
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger('pre_commit')
|
logger = logging.getLogger('pre_commit')
|
||||||
|
|
@ -272,7 +272,7 @@ def run(
|
||||||
args: argparse.Namespace,
|
args: argparse.Namespace,
|
||||||
environ: EnvironT = os.environ,
|
environ: EnvironT = os.environ,
|
||||||
) -> int:
|
) -> int:
|
||||||
no_stash = args.all_files or bool(args.files)
|
stash = not args.all_files and not args.files
|
||||||
|
|
||||||
# Check if we have unresolved merge conflict files and fail fast.
|
# Check if we have unresolved merge conflict files and fail fast.
|
||||||
if _has_unmerged_paths():
|
if _has_unmerged_paths():
|
||||||
|
|
@ -281,7 +281,7 @@ def run(
|
||||||
if bool(args.source) != bool(args.origin):
|
if bool(args.source) != bool(args.origin):
|
||||||
logger.error('Specify both --origin and --source.')
|
logger.error('Specify both --origin and --source.')
|
||||||
return 1
|
return 1
|
||||||
if _has_unstaged_config(config_file) and not no_stash:
|
if stash and _has_unstaged_config(config_file):
|
||||||
logger.error(
|
logger.error(
|
||||||
f'Your pre-commit configuration is unstaged.\n'
|
f'Your pre-commit configuration is unstaged.\n'
|
||||||
f'`git add {config_file}` to fix this.',
|
f'`git add {config_file}` to fix this.',
|
||||||
|
|
@ -293,12 +293,10 @@ def run(
|
||||||
environ['PRE_COMMIT_ORIGIN'] = args.origin
|
environ['PRE_COMMIT_ORIGIN'] = args.origin
|
||||||
environ['PRE_COMMIT_SOURCE'] = args.source
|
environ['PRE_COMMIT_SOURCE'] = args.source
|
||||||
|
|
||||||
if no_stash:
|
with contextlib.ExitStack() as exit_stack:
|
||||||
ctx = noop_context()
|
if stash:
|
||||||
else:
|
exit_stack.enter_context(staged_files_only(store.directory))
|
||||||
ctx = staged_files_only(store.directory)
|
|
||||||
|
|
||||||
with ctx:
|
|
||||||
config = load_config(config_file)
|
config = load_config(config_file)
|
||||||
hooks = [
|
hooks = [
|
||||||
hook
|
hook
|
||||||
|
|
@ -316,3 +314,6 @@ def run(
|
||||||
install_hook_envs(hooks, store)
|
install_hook_envs(hooks, store)
|
||||||
|
|
||||||
return _run_hooks(config, hooks, args, environ)
|
return _run_hooks(config, hooks, args, environ)
|
||||||
|
|
||||||
|
# https://github.com/python/mypy/issues/7726
|
||||||
|
raise AssertionError('unreachable')
|
||||||
|
|
|
||||||
|
|
@ -40,11 +40,6 @@ def clean_path_on_failure(path: str) -> Generator[None, None, None]:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
|
||||||
def noop_context() -> Generator[None, None, None]:
|
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def tmpdir() -> Generator[str, None, None]:
|
def tmpdir() -> Generator[str, None, None]:
|
||||||
"""Contextmanager to create a temporary directory. It will be cleaned up
|
"""Contextmanager to create a temporary directory. It will be cleaned up
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue