Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d7dee32

Browse files
committed
make --hook-dir optional for hook-impl
1 parent 965aeb1 commit d7dee32

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

pre_commit/commands/hook_impl.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
def _run_legacy(
1818
hook_type: str,
19-
hook_dir: str,
19+
hook_dir: str | None,
2020
args: Sequence[str],
2121
) -> tuple[int, bytes]:
2222
if os.environ.get('PRE_COMMIT_RUNNING_LEGACY'):
@@ -33,6 +33,9 @@ def _run_legacy(
3333
else:
3434
stdin = b''
3535

36+
if hook_dir is None: # git 2.54+ hooks
37+
return 0, stdin
38+
3639
# not running in legacy mode
3740
legacy_hook = os.path.join(hook_dir, f'{hook_type}.legacy')
3841
if not os.access(legacy_hook, os.X_OK):
@@ -259,7 +262,7 @@ def hook_impl(
259262
config: str,
260263
color: bool,
261264
hook_type: str,
262-
hook_dir: str,
265+
hook_dir: str | None,
263266
skip_on_missing_config: bool,
264267
args: Sequence[str],
265268
) -> int:

tests/commands/hook_impl_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ def test_run_legacy_does_not_exist(tmpdir):
6363
assert (retv, stdin) == (0, b'')
6464

6565

66+
def test_run_legacy_git_2_54():
67+
retv, stdin = hook_impl._run_legacy('pre-commit', None, ())
68+
assert (retv, stdin) == (0, b'')
69+
70+
6671
def test_run_legacy_executes_legacy_script(tmpdir, capfd):
6772
hook = tmpdir.join('pre-commit.legacy')
6873
hook.write('#!/usr/bin/env bash\necho hi "$@"\nexit 1\n')

0 commit comments

Comments
 (0)