1
0
mirror of https://github.com/j178/prek.git synced 2026-04-25 02:11:36 +02:00

215 Commits

Author SHA1 Message Date
Jo 58b39b29e6 Add auto-update --exit-code to exit with non-zero on updates (#2002)
## Summary

- add `prek auto-update --exit-code` to return status 1 when updates are
available
- keep `--check` as an alias for `--dry-run --exit-code`

Closes #2001
2026-04-24 14:48:17 +08:00
Jo 09f36b0550 Update project slogan (#2000)
Update the project slogan across docs, CLI, and package metadata.
2026-04-24 12:14:23 +08:00
Jo fc57592f32 Clarify pass_filenames concurrency docs (#1999)
Clarify that `pass_filenames: n` splits matching files across multiple
invocations.

Closes #1998
2026-04-24 11:05:43 +08:00
Jo fc0337b2e6 Clarify hook author manifest env docs (#1991) 2026-04-22 17:28:13 +08:00
Jo 6079531a5f Add auto-update --include-tag <pattern>/--exclude-tag <pattern> to filter tags (#1984)
Stacked on #1983.

Adds glob-based tag filters for `prek auto-update`:

- `--include-tag <pattern>` and `--exclude-tag <pattern>` apply to all
repositories.
- `--repo-include-tag <repo>=<pattern>` and `--repo-exclude-tag
<repo>=<pattern>` apply to a single repository.

Filters are applied before selecting the update candidate, with include
filters evaluated before exclude filters.

Closes #1972
Closes #174
2026-04-22 11:41:45 +08:00
Jo 37ef36f4a3 Add auto-update --exclude-repo <repo> to skip repos (#1983)
Adds `prek auto-update --exclude-repo <repo>` as an opt-out repository
filter.

The new flag can be repeated and is applied before repository fetches
are scheduled, so skipped repositories are not cloned or evaluated.

Closes #1972
2026-04-22 02:35:05 +08:00
Jo 78d0a438db docs: explain prek name (#1980)
For#1978.
2026-04-22 00:13:36 +08:00
Jo 1981c51f59 Bump version to 0.3.10 2026-04-21 19:12:54 +08:00
Jo 58dccaee20 Document gh skill install j178/prek prek to install prek skill for agents (#1951) 2026-04-18 17:23:38 +08:00
Jo 4fcbabc137 Improve compatibility and migration docs (#1940)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-04-14 11:48:55 +08:00
Jo 393d0ad41d Improve merge conflict marker detection (#1937)
## Summary

- make `check-merge-conflict` detect conflict blocks contextually
instead of flagging any bare `=======`
- add support for diff3 ancestor markers (`|||||||`)

Closes #1924 
Closes #1523
2026-04-14 10:59:51 +08:00
Jo 501d1db943 Bump version to 0.3.9 (#1934) 2026-04-13 17:33:35 +08:00
Sadjow Leão dc98c4792d Honor repo and worktree core.hooksPath (#1892)
## Summary

This takes a smaller approach than #1673.

Instead of mutating Git config during install, it lets `prek` ask Git
for the effective hooks directory and:

- honors repo-local (`git config --local`) `core.hooksPath`
- honors worktree-local (`git config --worktree`) `core.hooksPath`
- continues to refuse global/system `core.hooksPath` by default
- aligns `prek uninstall` with the same behavior
- updates the CLI reference and FAQ to document the behavior

This keeps the existing safety boundary for externally configured hook
locations while making linked worktrees and repo-owned hook directories
work without extra wrapper logic.

## Testing

- `cargo test -p prek --test install`
- `PREK_GENERATE=1 cargo test --bin prek
cli::_gen::generate_cli_reference -- --exact`

## Context

Closes #1672
Closes #1673

---------

Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2026-04-13 17:11:44 +08:00
Jo 90046cee4f Check and sync frozen comments during auto-update (#1896)
## Summary

`auto-update` now validates existing `# frozen:` comments against the
commit pinned in `rev`.

If the frozen comment is stale:
- in normal update mode, `auto-update` updates it to a matching ref when
possible, or removes it if no ref points to the pinned commit
- in `--dry-run`, it only reports the mismatch and does not modify the
config file
- in `--check`, it behaves like `--dry-run` and exits with status 1 if
updates would be made

This keeps frozen comments consistent with pinned SHA revisions without
adding a separate command.

## Example
```console
❯ cargo run -- auto-update --check                                                                                                                                                                                                                                                                                        
warning: [https://github.com/crate-ci/typos] frozen ref `v1.0` does not match `1111111111111111111111111111111111111111`
  --> .pre-commit-config.yaml:18:63
   |
18 |     rev: '1111111111111111111111111111111111111111' # frozen: v1.0
   |                                                               ^^^^ `v1.0` could not be resolved
   |
   = note: pinned commit `1111111111111111111111111111111111111111` does not exist in the repo
```
Closes #1864
2026-04-08 16:24:56 +08:00
Jo a33a9591b6 Manage Python tooling with uv dependency groups (#1910) 2026-04-06 21:40:01 +08:00
Jo 6fa77cc904 Enable renovate lock file maintenance 2026-04-06 20:45:17 +08:00
Jo 184f0a506e Update prek slogon (#1900) 2026-04-06 18:16:14 +08:00
Jo 24657c5908 Bump docs requirements (#1880) 2026-04-01 19:51:28 +08:00
Nathan McDougall 9ec64cd097 Update docs for case of hooks modifying files with a non-zero exit code (#1879)
See https://github.com/j178/prek/issues/1868 for context.
2026-04-01 17:26:07 +08:00
Jo 434db54b59 Refine dotnet SDK version handling and tests (#1870) 2026-03-30 22:41:07 +08:00
Thomas Carroll 5c426d2c74 Add language: dotnet support (#1783)
Hi, I thought I'd give a stab at dotnet support for prek. Not really an
amazing language for how it manages tools & its toolchain, so perhaps
some nastiness. Seems to work for `csharpier` at least for me.

There's some missing tests around the windows part of the code in the
coverage but I didn't want to get into messing with CI for windows
runners, maybe we can drop the powershell stuff if we make windows
people run in a bash type environment?

Not very versed in rust but hoping that even if stuff's bad there's a
bit of a start for someone better than I to have a stab at.

closes #48

---------

Co-authored-by: Thomas Carroll <thomas.carroll@kroll.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-03-30 22:41:07 +08:00
RicardoVercetti b13d37887b Add forbid-new-submodules as builtin hook (#1853)
for #1849

## Summary:
- Added the pre-commit `forbid_new_submodule` hook

## Usage:

```yaml
repos:
  - repo: builtin
    hooks:
      - id: forbid-new-submodules
```

---------

Co-authored-by: Jehoniah <aaram@appliedpaymentstech.com>
Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2026-03-25 17:59:39 +08:00
Jo bf09a45e64 Add prek run --no-fail-fast to override config file (#1859) 2026-03-24 17:57:22 +08:00
Jo bb412c0808 Bump version to 0.3.8 (#1858)
Republish 0.3.7 due to a publish process failure.
2026-03-23 16:08:10 +08:00
Jo 1dbec0c329 Bump version to 0.3.7 (#1856) 2026-03-23 15:26:12 +08:00
Felix Blom ba62c04078 Add pretty_format_json as builtin hook (#915)
## Description

Following the information provided in
[880](https://github.com/j178/prek/issues/880). This is an
implementation of the `pretty-format-json` hook.

The
[pretty-format-json](https://grep.app/search?f.path.pattern=.pre-commit-config.yaml&q=pretty-format-json)
has 1k grep.app hits. It's the final unimplemented hook used by
`airflow` as mentioned in [this
comment](https://github.com/j178/prek/issues/880#issuecomment-3405716137).

----

##  Notes

- **Preserve JSON Order**  
- Added the `preserve_order` feature to `serde_json`. This prevents
`serde` from automatically ordering JSON data, which is important for
comparisons with older implementations.
  - This change does not appear to affect other tests/features.  
- By default, `serde` uses a `BTreeMap` for `Object`. Enabling
`preserve_order` switches it to `IndexMap`.
  - This keeps the sorting logic within the `sort-keys` argument.

- **Git-Style Diff with `similar`**  
  - Added the `similar` library to perform git-style diff checks.  
  - Binary size increase is minimal.  
- Useful as a general utility and could be leveraged in other parts of
the project, maybe needed to be relocated?
- Added color highlighting to the diffs, improving readability compared
to original `pre-commit`.


```bash
cargo clean
cargo build --release 
```
- Master branch:  **8.49 MB**
- Feature branch: **8.55 MB**
- **+66,176 bytes** (**+0.74%**) increase from master to feature branch

_Q: why is my size so much smaller than both sizes mentioned
[here](https://github.com/j178/prek/pull/884#issuecomment-3406885242)?_

-----

### Performance

Ran these commands on the `airflow` repository:
```bash
# old
pre-commit run pretty-format-json --all-files --verbose
Format JSON files........................................................Passed
- hook id: pretty-format-json
- duration: 0.03s

# Old prek implementation (python)
prek run pretty-format-json --all-files --verbose
Format JSON files........................................................Passed
- hook id: pretty-format-json
- duration: 0.03s

# New implementation (rust)
prek run pretty-format-json --all-files --verbose
Format JSON files........................................................Passed
- hook id: pretty-format-json
- duration: 0.00s
```

## Output
Old pre-commit:
<img width="601" height="376" alt="image"
src="https://github.com/user-attachments/assets/f0553015-24cf-4d23-98e8-2759f912c9b3"
/>

New:
<img width="707" height="430" alt="image"
src="https://github.com/user-attachments/assets/fa7ce303-caa9-4139-9e77-6e58db5f0725"
/>

Where both would autofix to the same:
<img width="349" height="304" alt="image"
src="https://github.com/user-attachments/assets/67baf526-787b-4aa6-a0fe-7859a2a5fb8b"
/>

---------

Co-authored-by: Felix Blom <70511386+Felix-Blom@users.noreply.github.com>
Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2026-03-23 14:58:11 +08:00
Jo 24f2d627bf Add destroyed-symlinks builtin hook (#1851)
Closes #1848

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-03-22 21:19:50 +08:00
Jo fc529df132 Add check-shebang-scripts-are-executable builtin hook (#1847) 2026-03-22 00:59:38 +08:00
Jo addddb8989 Add file-contents-sorter as builtin hook (#1846)
Closes #1843
2026-03-21 23:42:44 +08:00
Matt Van Horn cb3f71c322 Add check-vcs-permalinks as builtin hook (#1842)
## Summary

Add a native Rust fast path for the `check-vcs-permalinks` hook from
`pre-commit/pre-commit-hooks`.

## Why this matters

Without a fast path, prek must clone the `pre-commit/pre-commit-hooks`
repo, install Python, and run the hook script. The native implementation
avoids that overhead for a simple regex-based check.

## Changes

- New file:
`crates/prek/src/hooks/pre_commit_hooks/check_vcs_permalinks.rs`
- Port of the [upstream Python
implementation](https://github.com/pre-commit/pre-commit-hooks/blob/main/pre_commit_hooks/check_vcs_permalinks.py)
- Detects GitHub blob URLs that use a branch name (e.g. `main`,
`master`) instead of a commit hash, combined with a `#L` line number
anchor
- Scans files concurrently using the existing
`run_concurrent_file_checks` helper
  - Reports file path, line number, and offending line content
  - Includes unit tests for permalinks, branch links, and edge cases
- Updated `crates/prek/src/hooks/pre_commit_hooks/mod.rs`: added
`CheckVcsPermalinks` variant

## Testing

- `cargo check -p prek` passes
- Unit tests verify both positive (branch link) and negative (commit
hash permalink) cases

Fixes #1833

This contribution was developed with AI assistance (Claude Code).

---------

Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2026-03-21 22:54:25 +08:00
Matt Van Horn 307254d3fc Add check-illegal-windows-names as builtin hook (#1841)
## Summary

Add a native Rust fast path for the `check-illegal-windows-names` hook
from `pre-commit/pre-commit-hooks`.

## Why this matters

Without a fast path, prek must clone the `pre-commit/pre-commit-hooks`
repo and parse `.pre-commit-hooks.yaml` just to run a regex-based
filename check. The native implementation skips that overhead entirely.

## Changes

- New file:
`crates/prek/src/hooks/pre_commit_hooks/check_illegal_windows_names.rs`
- Uses the same regex from upstream's
[`.pre-commit-hooks.yaml`](https://github.com/pre-commit/pre-commit-hooks/blob/f1dff44d3a9ae852957f34def96390f28719c232/.pre-commit-hooks.yaml#L49)
- Detects reserved names (CON, PRN, AUX, NUL, COM1-9, LPT1-9), illegal
characters (<>:"|?*), control characters, and trailing dots/spaces
- Includes unit tests for legal filenames, reserved names, illegal
characters, and trailing dots/spaces
- Updated `crates/prek/src/hooks/pre_commit_hooks/mod.rs`: added
`CheckIllegalWindowsNames` variant to enum and wired up the `run`
dispatch

## Testing

- `cargo check -p prek` passes
- Unit tests cover legal names, reserved names, illegal characters, and
trailing dots/spaces

Fixes #1835

This contribution was developed with AI assistance (Claude Code).

---------

Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2026-03-21 22:43:51 +08:00
Shaan Majid 2b811fb6a2 Add language: deno support (#1516)
---------

Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
Co-authored-by: Janosh Riebesell <janosh.riebesell@gmail.com>
2026-03-20 09:24:24 +08:00
Daisuke Sato 47c017a6e8 Add --all flag to prek uninstall (#1817)
## Summary

  Closes #1779

- Add `--all` flag to `prek uninstall` that scans the hooks directory
and removes every prek-managed hook (detected via `is_our_script()`),
regardless of hook type
- Without `--all`, behavior is unchanged: uses `-t` or
`default_install_hook_types`, falls back to `pre-commit`
  - `--all` and `-t` are mutually exclusive (`conflicts_with`)
- Suppress "not managed" / "does not exist" skip messages when `--all`
is used, since iterating all hook types will naturally hit many
non-existent ones

  ## Tests

- `uninstall_all_managed_hooks`: `--all` removes all prek-managed hooks
- `uninstall_all_no_hooks`: `--all` exits cleanly when no hooks are
installed
  - Ran `mise run lint` and confirmed no errors

---------

Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2026-03-18 13:09:46 +08:00
Jo dd53c3d715 Bump version to 0.3.6 (#1811) 2026-03-16 16:18:06 +08:00
Jo c29d89a65d Allow selectors for hook ids containing colons (#1782)
Closes #1781
2026-03-13 22:20:27 +08:00
Jo 4ed4e8660a Disambiguate “hook” terminology by renaming "Git hooks" to "Git shims" (#1776)
Closes #1775
2026-03-11 11:46:52 +08:00
Jo ec2c03f7c2 Document compatibility with pre-commit (#1767) 2026-03-10 13:06:27 +08:00
Jo 9009dc0fd8 Rename prek install-hooks to prek prepare-hooks, prek install --install-hooks to prek install --prepare-hooks (#1766)
This renames the hook environment setup surface from `install-hooks` to
`prepare-hooks` to make the distinction between two different actions
clearer:

- `prek install` installs Git hook shims under .git/hooks
- `prek prepare-hooks` prepares the managed hook environments and caches

The old naming used "install" for both concepts, which was easy to
misread, especially in forms like `prek install --install-hooks`. The
new names make the behavior more explicit:

- prek install --prepare-hooks
- prek prepare-hooks

Compatibility is preserved, so existing workflows continue to work.

Closes #1762
2026-03-10 13:06:01 +08:00
Pablo Castellazzi 9028e0d312 Update configuration.md with TOML 1.1 notes (#1764)
TOML 1.1 is not yet universally available. This hit me on Visual Studio
Code using [Even Better
TOML](https://marketplace.visualstudio.com/items?itemName=tamasfe.even-better-toml).
While this issue does not affect `prek` directly, users may encounter
errors on their IDE/editor and wonder what is going on.
2026-03-10 11:07:24 +08:00
Jo 6d07a0e112 Retry auth-failed repo clones with terminal prompts enabled (#1761)
When a repo clone fails because authentication is required, retry that
clone with `GIT_TERMINAL_PROMPT=1` so Git can prompt the user for
credentials.

The retry flow keeps the initial clone pass non-interactive, detects
auth-related failures, and then retries only those failed clones with
terminal prompts enabled. Retries run sequentially so users only see one
credential prompt at a time and know which repository is requesting
authentication.

Closes #1634
Closes #1173
Related #1193
Related #1472
2026-03-09 23:03:53 +08:00
Jo 46cb7bad13 Bump version to 0.3.5 (#1760) 2026-03-09 18:17:03 +08:00
Jo 1bead452d8 Improve docs for Rust cli: dependencies (#1748) 2026-03-06 21:25:54 +08:00
Jo 03d1f87e9f rust: support cli: git dependency 4th segment package disambiguation (#1747)
Fixes #1682
Extends #1256

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-03-06 20:44:06 +08:00
Dev-iL 176879a471 Bump zensical to 0.0.24 (#1734)
Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2026-03-02 15:37:39 +08:00
Dev-iL 2df575becf Update documentation for --stage option (#1727)
Replaced a duplicated "pre-commit" in instructions by "pre-push"

---------

Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2026-03-02 15:37:23 +08:00
is-alnilam e993b04305 Add automatic Ruby download support using rv binaries (#1668)
Current Ruby support can only use Ruby interpreters which are already
installed on the system, although it goes to great lengths to find
interpreters installed by a variety of Ruby managers. This change adds
support for installing new interpreters using the binaries delivered by
the `rv` team. `rv` only provide installers for versions of Ruby still
actively supported (so they don't offer version 3.1, for example), and
only build for a subset of all Ruby-supported platforms. If users need
an unsupported version of Ruby or wish to use an unsupported platform,
they will be prompted to download and install a version of Ruby
manually.

`rv` bundles are named according to the platform, currently including
these components in the filename:
- x86_64_linux
- arm64_linux
- x86_64_linux_musl
- arm64_linux_musl
- ventura (used for macOS on x86_64)
- arm64_sonoma (used for macOS on 64-bit ARM)

If and when upstream `rv` changes these names, the detection code will
need to be updated to match. In particular, this includes the use of
macOS codenames, as if `rv` stop releasing a 'sonoma' package, this will
block installing the macOS versions of Ruby. Currently `rv` seem to be
attempting to keep these codenames, as they already rename their x86_64
builds from 'sequoia' (macOS 15) to 'ventura' (macOS 13). Adding a new
CPU architecture (such as RISC-V) would also need changes, but wouldn't
break existing platform support.

Ruby versions are found by querying the GitHub Releases API, searching
the options returned for an installer that matches the platform and
version requirements, then, if found, downloading and unpacking into the
`prek` tools folder. The `PREK_RUBY_MIRROR` environment variable can be
used to point to a different source for installers, for example to
support mirrors or air-gapped CI environments. Mirrors need to follow
the GitHub URL patterns, but note that although the GitHub hostname
changes between `api.github.com` and `github.com` as needed, any
non-GitHub mirror server will not be remapped in this manner. Where Ruby
is being downloaded from GitHub (either from the upstream `rv` or a
mirror), this remapping does occur, and any `GITHUB_TOKEN` will be sent
with the requests. This both limits impact of rate limiting, and also
allows a private GitHub repository to be used (e.g. for a vetted subset
of `rv` rubies to be mirrored). Note that GitHub tokens will only be
sent to mirrors which are hosted on GitHub.

To allow for passing the `GITHUB_TOKEN` in download requests, the
generic `download_and_extract` function is now a wrapper over a version
which takes an extension function, with the default function not
extending the request. The Ruby code will add the GitHub token if the
request is to GitHub.

Closes #43
Closes #765

---------

Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2026-03-01 23:03:29 +08:00
Jo 7df258770a Expose --git-dir to force hook installation target (#1723) 2026-03-01 22:27:05 +08:00
Jo 04b1308c98 Bump version to 0.3.4 (#1703) 2026-02-28 11:34:08 +08:00
JP-Ellis ce3ecf3d01 Allow pass_filenames to accept a positive integer (#1698)
Setting `pass_filenames: n` limits each hook invocation to at most `n`
filenames, with multiple parallel invocations for larger file sets. This
mirrors the `-n` flag of `xargs` and is useful for tools that can only
process a limited number of files per invocation (typically, if a limit
applies, it is 1).

The existing boolean behaviour is preserved: `true` passes all filenames
(default) and `false` passes none. So this is a backwards compatible
change.

Resolves: #1471

---------

Signed-off-by: JP-Ellis <josh@jpellis.me>
2026-02-28 10:43:45 +08:00
Doug Richardson 91a1faedcc Add PREK_MAX_CONCURRENCY environment variable (#1697)
## Summary

- Add `PREK_MAX_CONCURRENCY` environment variable to cap the maximum
number of concurrent hooks
- Value is floored at 1; values above CPU count are allowed (useful for
I/O-bound hooks)
- Invalid values show a user-visible warning and fall back to CPU count
- `PREK_NO_CONCURRENCY` takes precedence when both are set

## Motivation

When `ulimit -n` is low, concurrent hook execution can exhaust file
descriptors. This provides an environment variable to limit concurrency.

For #1696

## Test plan

- [x] `mise run lint` — no warnings
- [x] `mise run test` — all tests pass
- [x] Unit tests for `resolve_concurrency`: valid value, above CPU
count, zero floors to 1, invalid string, empty string, unset,
no_concurrency, no_concurrency overrides max

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-27 12:01:53 +08:00