diff --git a/README.md b/README.md index d7ff74e..5bb07ec 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ PDM and Poetry plugin to sync your pre-commit versions with your lockfile and au - ⏩ Run every time you run the lockfile is updated, not as a pre-commit hook - 🔄 Install pre-commit hooks automatically, no need to run `pre-commit install` manually - 💫 Preserve your pre-commit config file formatting +- ✨ Support [prek](https://prek.j178.dev/) configuration files (preserve `prek` specific keys) - 🍃 Lightweight, only depends on [strictyaml](https://pypi.org/project/strictyaml/) and [packaging](https://pypi.org/project/packaging/) ## Supported versions @@ -87,6 +88,7 @@ disable-sync-from-lock = false # Packages to ignore when syncing from lock ignore = [] # Name of the pre-commit config file to sync with +# Can be set to ".pre-commit-config.yml" to support prek alternate config file pre-commit-config-file = ".pre-commit-config.yaml" # Additional mapping of URLs to python packages # Default is empty, but will merge with the default mapping diff --git a/tests/test_pre_commit_config_file.py b/tests/test_pre_commit_config_file.py index a4d59bf..50fd877 100644 --- a/tests/test_pre_commit_config_file.py +++ b/tests/test_pre_commit_config_file.py @@ -190,3 +190,46 @@ def test_update_additional_dependencies_versions(base: str) -> None: def test_precommit_repo_equality(repo1: PreCommitRepo, repo2: PreCommitRepo, equal: bool): assert (repo1 == repo2) is equal assert (hash(repo1) == hash(repo2)) is equal + + +def test_prek_config_support() -> None: + # A config file with prek-specific keys + file_content = """\ +minimum_prek_version: "0.1.0" +orphan: true +repos: + - repo: https://github.com/psf/black + rev: 23.3.0 + hooks: + - id: black + priority: 10 + env: + FOO: bar +""" + mock_path = MagicMock(spec=Path) + mock_path.open = mock_open(read_data=file_content) + + config = PreCommitHookConfig.from_yaml_file(mock_path) + + updated_repo = PreCommitRepo( + "https://github.com/psf/black", + "23.4.0", + [PreCommitHook("black")], + ) + + mock_path.open = mock_open() + config.update_pre_commit_repo_versions({config.repos[0]: updated_repo}) + + expected_content = """\ +minimum_prek_version: "0.1.0" +orphan: true +repos: + - repo: https://github.com/psf/black + rev: 23.4.0 + hooks: + - id: black + priority: 10 + env: + FOO: bar +""" + mock_path.open().writelines.assert_called_once_with(expected_content.splitlines(keepends=True))