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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
make --hook-dir optional for hook-impl
  • Loading branch information
asottile committed Apr 21, 2026
commit d7dee322abfc765b042f2e3b872aab3c3a867610
7 changes: 5 additions & 2 deletions pre_commit/commands/hook_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

def _run_legacy(
hook_type: str,
hook_dir: str,
hook_dir: str | None,
args: Sequence[str],
) -> tuple[int, bytes]:
if os.environ.get('PRE_COMMIT_RUNNING_LEGACY'):
Expand All @@ -33,6 +33,9 @@ def _run_legacy(
else:
stdin = b''

if hook_dir is None: # git 2.54+ hooks
return 0, stdin

# not running in legacy mode
legacy_hook = os.path.join(hook_dir, f'{hook_type}.legacy')
if not os.access(legacy_hook, os.X_OK):
Expand Down Expand Up @@ -259,7 +262,7 @@ def hook_impl(
config: str,
color: bool,
hook_type: str,
hook_dir: str,
hook_dir: str | None,
skip_on_missing_config: bool,
args: Sequence[str],
) -> int:
Expand Down
5 changes: 5 additions & 0 deletions tests/commands/hook_impl_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ def test_run_legacy_does_not_exist(tmpdir):
assert (retv, stdin) == (0, b'')


def test_run_legacy_git_2_54():
retv, stdin = hook_impl._run_legacy('pre-commit', None, ())
assert (retv, stdin) == (0, b'')


def test_run_legacy_executes_legacy_script(tmpdir, capfd):
hook = tmpdir.join('pre-commit.legacy')
hook.write('#!/usr/bin/env bash\necho hi "$@"\nexit 1\n')
Expand Down
Loading