(
hook_type: str,
hook_dir: str | None,
args: Sequence[str],
)
| 15 | |
| 16 | |
| 17 | def _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 | |
| 49 | def _validate_config( |
no test coverage detected