pre-commit hook to ensure your Swift project's
Package.resolved file stays consistent and up-to-date.
- Shell 100%
| .pre-commit-config.yaml | ||
| .pre-commit-hooks.yaml | ||
| example-config.yaml | ||
| README.md | ||
| swift-resolve-check | ||
Swift Package Resolve Check Pre-commit Hook
This repository provides a pre-commit hook to ensure your Swift project's Package.resolved file stays consistent and up-to-date.
What does it do?
The swift-resolve-check hook runs swift package resolve and checks if your Package.resolved file changes as a result. It can either:
- Fail (default): Block the commit if
Package.resolvedchanges after resolving dependencies. - Update: Automatically update
Package.resolvedand allow the commit to proceed.
It supports custom package paths and custom Swift executables.
Installation
-
Install pre-commit:
pip install pre-commit -
Add this hook to your
.pre-commit-config.yaml:- repo: https://github.com/noahkamara/swift-resolve-check rev: v0.1.0 hooks: - id: swift-resolve-check # Optionally pass args, e.g. --update or --package-path ExamplePackage # args: [--update] -
Install the hooks:
pre-commit install
Usage
By default, the hook will block commits if Package.resolved changes after running swift package resolve. You can configure the behavior:
-
Fail on change (default):
git commit # If Package.resolved changes, the commit is blocked. -
Auto-update on change: In your
.pre-commit-config.yaml:- repo: local hooks: - id: swift-resolve-check args: [--update] -
Custom package path or Swift executable:
- repo: local hooks: - id: swift-resolve-check args: [--package-path, DocsyLib, --swift, /path/to/swift]
Run
- Run the hook:
pre-commit run swift-resolve-check
More info
See pre-commit.com for more details on configuring and using pre-commit hooks.