precommit.star¶
Read and bump hook revisions in .pre-commit-config.yaml.
Edits are line-based, so comments and layout stay as they were.
| Function | What it does |
|---|---|
revs |
Reads the revision each hook repository is pinned to. |
set_rev |
Pins a hook repository to a new revision, keeping quotes and comments. |
revs¶
Reads the revision each hook repository is pinned to.
Arguments
| Name | Description |
|---|---|
repo |
The repo passed to change(repo). |
path |
The pre-commit config to read. |
Returns: A dict of repository URL to rev, in file order.
Example
revs(repo)
# returns {"https://github.com/pre-commit/pre-commit-hooks": "v4.6.0", "https://github.com/psf/black": "24.4.0"}
Used in: pre-commit-rev
set_rev¶
Pins a hook repository to a new revision, keeping quotes and comments.
The URL matches with or without a trailing .git. A config that does
not use the repository is left alone, and so is a newer rev.
Arguments
| Name | Description |
|---|---|
repo |
The repo passed to change(repo). |
url |
The hook repository URL. |
rev |
The new revision, such as v5.0.0. |
path |
The pre-commit config to edit. |
Returns: True when the file changed.
Example
Used in: pre-commit-rev