Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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
7 changes: 5 additions & 2 deletions 7 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 5 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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.