MCPcopy Index your code
hub / github.com/pre-commit/pre-commit / _run_legacy

Function _run_legacy

pre_commit/commands/hook_impl.py:17–46  ·  view source on GitHub ↗
(
        hook_type: str,
        hook_dir: str | None,
        args: Sequence[str],
)

Source from the content-addressed store, hash-verified

15
16
17def _run_legacy(
18 hook_type: str,
19 hook_dir: str | None,
20 args: Sequence[str],
21) -> tuple[int, bytes]:
22 if os.environ.get('PRE_COMMIT_RUNNING_LEGACY'):
23 raise SystemExit(
24 f"bug: pre-commit's script is installed in migration mode\n"
25 f'run `pre-commit install -f --hook-type {hook_type}` to fix '
26 f'this\n\n'
27 f'Please report this bug at '
28 f'https://github.com/pre-commit/pre-commit/issues',
29 )
30
31 if hook_type == 'pre-push':
32 stdin = sys.stdin.buffer.read()
33 else:
34 stdin = b''
35
36 if hook_dir is None: # git 2.54+ hooks
37 return 0, stdin
38
39 # not running in legacy mode
40 legacy_hook = os.path.join(hook_dir, f'{hook_type}.legacy')
41 if not os.access(legacy_hook, os.X_OK):
42 return 0, stdin
43
44 with envcontext((('PRE_COMMIT_RUNNING_LEGACY', '1'),)):
45 cmd = normalize_cmd((legacy_hook, *args))
46 return subprocess.run(cmd, input=stdin).returncode, stdin
47
48
49def _validate_config(

Callers 1

hook_implFunction · 0.85

Calls 3

envcontextFunction · 0.90
normalize_cmdFunction · 0.90
getMethod · 0.45

Tested by

no test coverage detected