diff --git a/pre_commit/languages/powershell.py b/pre_commit/languages/powershell.py new file mode 100644 index 00000000..081c6930 --- /dev/null +++ b/pre_commit/languages/powershell.py @@ -0,0 +1,21 @@ +from __future__ import annotations + +from typing import Sequence + +from pre_commit.hook import Hook +from pre_commit.languages import helpers + + +ENVIRONMENT_DIR = None +get_default_version = helpers.basic_get_default_version +healthy = helpers.basic_healthy +install_environment = helpers.no_install + +def run_hook( + hook: Hook, + file_args: Sequence[str], + color: bool, +) -> tuple[int, bytes]: # pragma: win32 no cover + fullpath = (hook.prefix.prefix_dir + '\\' + hook.cmd[0]) + cmd = ('pwsh', '-F') + (fullpath,) + return helpers.run_xargs(hook, cmd, file_args, color=color) diff --git a/testing/gen-languages-all b/testing/gen-languages-all index dfd92c0e..d40c79fc 100755 --- a/testing/gen-languages-all +++ b/testing/gen-languages-all @@ -5,8 +5,8 @@ import sys LANGUAGES = [ 'conda', 'coursier', 'dart', 'docker', 'docker_image', 'dotnet', 'fail', - 'golang', 'lua', 'node', 'perl', 'pygrep', 'python', 'r', 'ruby', 'rust', - 'script', 'swift', 'system', + 'golang', 'lua', 'node', 'perl', 'powershell', 'pygrep', 'python', 'r', + 'ruby', 'rust', 'script', 'swift', 'system', ] FIELDS = [ 'ENVIRONMENT_DIR', 'get_default_version', 'healthy', 'install_environment', diff --git a/testing/resources/powershell_repo/.pre-commit-hooks.yaml b/testing/resources/powershell_repo/.pre-commit-hooks.yaml new file mode 100644 index 00000000..32d60a6d --- /dev/null +++ b/testing/resources/powershell_repo/.pre-commit-hooks.yaml @@ -0,0 +1,6 @@ +- id: powershell-example-hook + name: Test Powershell Project + description: Test Powershell Project + entry: test-script.ps1 + language: powershell + stages: [commit] \ No newline at end of file diff --git a/testing/resources/powershell_repo/test-script.ps1 b/testing/resources/powershell_repo/test-script.ps1 new file mode 100644 index 00000000..92d8d50d --- /dev/null +++ b/testing/resources/powershell_repo/test-script.ps1 @@ -0,0 +1,2 @@ +Write-Output "Hello from Powershell" +exit 0 \ No newline at end of file diff --git a/tests/repository_test.py b/tests/repository_test.py index 5c7909c5..c6280715 100644 --- a/tests/repository_test.py +++ b/tests/repository_test.py @@ -1162,3 +1162,15 @@ def test_local_lua_additional_dependencies(store): ret, out = _hook_run(hook, (), color=False) assert b'Luacheck' in out assert ret == 0 + +@pytest.mark.parametrize( + 'repo', + ( + 'powershell_repo', + ), +) +def test_dotnet_hook(tempdir_factory, store, repo): + _test_hook_repo( + tempdir_factory, store, repo, + 'powershell-example-hook', [], b'Hello from Powershell\n', + )