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

50 Commits

Author SHA1 Message Date
Jo 67930321fb Align shell prek-only docs note 2026-04-24 21:53:41 +08:00
Jo b20b841702 Move unsupported shell details into docs notes 2026-04-24 20:34:56 +08:00
Jo e875985099 Document unsupported shell languages 2026-04-24 20:31:41 +08:00
Jo 70397a4058 Validate shell support by language 2026-04-24 20:22:39 +08:00
Jo 2b5981c931 Add explicit shell execution for hook entries
Introduce a typed shell option so hooks can opt into multiline shell-source execution without changing the default direct argv behavior. Shell adapters write entry content to temporary scripts and pass hook args and filenames through shell-specific argument conventions like "".
2026-04-24 19:59:17 +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
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 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
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
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
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
Copilot 8c926992c6 Make trace command logging truncation configurable via PREK_LOG_TRUNCATE_LIMIT (#1679)
Trace-level `Executing ...` lines currently truncate command arguments
at a hardcoded 120 characters, which hides critical details when
debugging hooks (notably `docker_image` entrypoint/args). This change
introduces a configurable truncate limit while preserving existing
default behavior.

- **Config surface: new env var**
  - Added `PREK_LOG_TRUNCATE_LIMIT` to `prek-consts` (`EnvVars`).

- **Runtime behavior in command logging**
- Updated `Cmd` display formatting in `crates/prek/src/process.rs` to
read truncation limit from `PREK_LOG_TRUNCATE_LIMIT`.
- Cached the resolved truncate limit with `LazyLock` so env parsing
happens once.
  - Kept default at `120` when unset/invalid.
- Treated `0` as invalid and fallback to default to avoid degenerate
output.

- **Documentation**
- Added `PREK_LOG_TRUNCATE_LIMIT` to `docs/configuration.md` under
environment variables, including default and intent.

- **Focused unit coverage**
  - Added tests for:
    - env var value parsing (valid/invalid/zero),
    - env-based resolution behavior,
    - cached-limit behavior via `LazyLock`,
    - env restoration guard to avoid cross-test env leakage.

```rust
const DEFAULT_COMMAND_LOG_TRUNCATE_LIMIT: usize = 120;
static COMMAND_LOG_TRUNCATE_LIMIT: LazyLock<usize> =
    LazyLock::new(command_log_truncate_limit_from_env);

fn command_log_truncate_limit() -> usize {
    *COMMAND_LOG_TRUNCATE_LIMIT
}
```

<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>

> 
> ----
> 
> *This section details on the original issue you should resolve*
> 
> <issue_title>Do not truncate trace run executions</issue_title>
> <issue_description>### Summary
> 
> I was trying to debug a docker_image hook execution and was delighted
to note the --log-file option.
> 
> However, turns out that the "Executing" TRACE run lines are truncated
with `[...]` before showing the part I'm actually interested in (a case
of tweaking entrypoints and arguments).
> 
> I'd suggest not truncating these lines in the trace log at all, or
providing an option not to truncate.
> 
> ### Willing to submit a PR?
> 
> - [ ] Yes — I’m willing to open a PR to fix this.
> 
> ### Platform
> 
> Ubuntu 25.10 amd64
> 
> ### Version
> 
> 0.3.2
> 
> ### .pre-commit-config.yaml
> 
> N/A
> 
> ### Log file
> 
> ```
> 2026-02-20T10:17:47.223740Z TRACE run{hook_id=...
language=docker_image}: Executing `cd ... && docker run --rm --tty
--user 1000:1000 --init --volume ...:/src:rw,Z --workdir /src
--entrypoint ... --network [...]`
> ```</issue_description>
> 
> <agent_instructions>Add a new env var to prek-consts, controlling the
command line log truncate limit in process.rs, current it is hardcoded
to 120. Document it in docs/configuration.md env vars
section.</agent_instructions>
> 
> ## Comments on the Issue (you are @copilot in this section)
> 
> <comments>
> </comments>
> 


</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes j178/prek#1678

<!-- START COPILOT CODING AGENT TIPS -->
---

🔒 GitHub Advanced Security automatically protects Copilot coding agent
pull requests. You can protect all pull requests by enabling Advanced
Security for your repositories. [Learn more about Advanced
Security.](https://gh.io/cca-advanced-security)

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: j178 <10510431+j178@users.noreply.github.com>
2026-02-20 20:51:49 +08:00
Tin Lai eb80de7b6c Match files/exclude filter against relative path of nested project (#1624)
Previously, in a setup that looks like
```
.
├── .pre-commit-config.yaml        # setting A (root)
└── mynestedrepo
    ├── .pre-commit-config.yaml    # setting B (nested repo)
    └── tobeexcluded
        └── nodonttrackthis.md
```
`mynestedrepo` is a nested folder using the **workspace** feature with a
nested `.pre-commit-config.yaml`. Ideally (especially in a monorepo
setup), it shouldn't need to care about any folder level above it.

Previously, if `mynestedrepo/.pre-commit-config.yaml` B contains
```yaml
exclude: (^tobeexcluded/)
repos:
  ...
```
one would expect `mynestedrepo/tobeexcluded` to be excluded. However,
the path passed from the filename filter previously uses the full path,
so it will still modify the `nodonttrackthis.md` file even though it
should be excluded.

Currently, the inner settings exclude pattern needs to specify either
`(^mynestedrepo/tobeexcluded/)` (which is not ideal if we want the inner
repo to be agnoistic to any folder above it) or `(tobeexcluded/)` (which
risk excluding some wanted folder if the exclude pattern is generic).

This PR makes it so that only the inner relative path is passed to the
filename filter.

----
i.e., instead of passing
`mynestedrepo/tobeexcluded/nodonttrackthis.md`
we pass
`tobeexcluded/nodonttrackthis.md`
to the inner project instead

---------

Signed-off-by: Tin Lai <tin@tinyiu.com>
Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2026-02-12 15:42:41 +08:00
Jo 8fdc71ddf5 Add "Willing to submit PR" checkbox to bug report form (#1611) 2026-02-09 16:33:26 +08:00
Jo 3fa9187f64 Add prek util yaml-to-toml to convert .pre-commit-config.yaml to prek.toml (#1584) 2026-02-06 16:11:01 +08:00
Jo 60eb3f47e7 Document that use --refresh to pick up .prekignore changes (#1575)
For https://github.com/j178/prek/issues/1522#issuecomment-3853425122
2026-02-05 21:24:31 +08:00
Jo 16f514bafd Move identify and init-template-dir under the prek util top-level command (#1574)
The old `prek init-template-dir` is hide but still works.
2026-02-05 19:39:52 +08:00
Jo 44ea4c9cab Update schema store url for prek 2026-02-05 17:43:55 +08:00
Jo d784a470f1 Add documentation about prek.toml (#1560)
update schema url
2026-02-05 17:10:30 +08:00
Jo 1539b5a210 Add document about authoring remote hooks (#1571) 2026-02-05 17:09:42 +08:00
Shaan Majid 73e14e65d3 Revert "Allow optional upgrade hints after semicolon in minimum_prek_version" (#1538) 2026-02-03 08:34:38 +08:00
Jo 1c1af94121 Allow optional upgrade hints after semicolon in minimum_prek_version (#1536)
Closes #1490
2026-02-02 22:35:12 +08:00
Aleksey f10ae08be6 Add PREK_QUIET environment variable support (#1513)
This PR addresses issue #1512 by adding `PREK_QUIET` environment
variable support for controlling quiet output mode (analogous to
`-q`/`-qq` flags).

Key changes include:
- `PREK_QUIET=1` -> quiet mode (like `-q`)
- `PREK_QUIET=2` -> silent mode (like `-qq`)
- Added integration tests and documentation
2026-02-01 09:40:21 +08:00
Jo 720c7cb732 Use git ls-remote --tags to list bun versions (#1439) 2026-01-22 11:05:41 +08:00
Shaan Majid 8d464397e6 Add language: bun support (#1411)
* feat(bun): add Bun language support

* test(bun): add integration tests for Bun language support

Add three integration tests covering the key functionality:
- basic_bun: simple hook execution using bun -e
- additional_dependencies: verify deps installed via bunx cowsay
- language_version: test version specification with language_version: "1"

The additional_dependencies test runs twice to verify health_check and
cache reuse works correctly.

* docs: add Bun to supported languages documentation

- Add Bun to toolchain list in README features section
- Add Bun to managed toolchain downloads list in languages.md
- Add full Bun language section with version format documentation

* ci: add Bun setup to test jobs

* feat(bun): use GITHUB_TOKEN to avoid API rate limits

When listing Bun versions from GitHub releases, use the GITHUB_TOKEN
environment variable if available to authenticate requests. This
increases the rate limit from 60 to 5,000 requests/hour.

GITHUB_TOKEN is automatically set in GitHub Actions workflows.

* fix(bun): use consistent bin_dir path on all platforms

Bun installs global packages to $BUN_INSTALL/bin/ on all platforms,
so bin_dir should always return prefix/bin. The Windows special case
was incorrectly copied from Node (which uses npm's different install
structure).

* Add toolchain download test

* Add tests

---------

Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2026-01-22 11:05:41 +08:00
Shaan Majid f5262b6b2c docs: fix HTML anchors, grammar, capitalization, and add missing tracking issues (#1448) 2026-01-22 02:06:13 +08:00
Jo 23b4456a80 Expand ~ tilde in PREK_HOME (#1431) 2026-01-21 11:35:52 +08:00
Matthias Schoettle 0784ddfaea Add mdformat pre-commit hook (#1416) 2026-01-20 11:26:37 +08:00
Jo 52c20ab065 Document language support details (#1380) 2026-01-17 17:48:11 +08:00
Jo 8c2580a12b Fix callout indentation (#1375) 2026-01-16 21:07:48 +08:00
Jo f6731ad435 Explain project configuration scope (#1373) 2026-01-16 19:09:44 +08:00
Na'aman Hirschfeld 392eb2d60c Add glob list support for file patterns (files and exclude) (#1197)
* feat: add glob list support for file patterns

# Conflicts:
#	docs/configuration.md

* Fix clippy warnings in config tests

* Add tests for glob file patterns

* chore: run cargo fmt

* test: make glob pattern test windows-friendly

* Fix CI: add globset dep and disable GPG signing in tests

* Update json schema

* Tweaks

* Update doc

* Update doc

---------

Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2026-01-16 16:59:26 +08:00
Jo b99d05c440 Complete configuration document (#1338) 2026-01-12 20:34:11 +08:00
Branch Vincent d0c33b1833 Support apple's container for docker lang (#1306)
* Support apple's `container` for docker lang

* Tweak

---------

Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2026-01-07 16:09:05 +08:00
Daniel Parks 0efd6370d7 Add env to set environment variables for hooks (#1279) (#1285)
* Add `env` to set environment variables for hooks (#1279)

This key is not supported by `pre-commit`.

* DO NOT MERGE: use my fork of prek-test-repos/script-hooks

* Update test

---------

Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2025-12-30 17:08:44 +08:00
Jo ae056aff2d Clarify priority scope across repos (#1251) 2025-12-21 14:17:14 +08:00
Jo 17a2f64eba Improve documentation for configurations (#1247) 2025-12-20 14:10:44 +08:00
Jo c7545d8edb Improve documentation for priority (#1245) 2025-12-20 12:46:10 +08:00
Jo 1c9d1f5618 Implement priority based parallel execution (#1232)
* Support priority-based parallel hook execution

* .

* .

* .

* .

* .

* Implement `priority` based parallel exeuction

* Reduce repeated code

* Add progress for processing files

* Improve sytling

* Tweak UI

* Fix UI

* Update snaps

* Update docs

* Add a test

* Update proposal

* Update crates/prek/src/config.rs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Apply review feedbacks

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-20 12:09:42 +08:00
joshuamarkovic 59230a7a72 Support orphan projects (#1129)
* Add deduplicate feature

# Conflicts:
#	src/cli/run/filter.rs

* Linting

* Linting

* Fix failed test

* Fix failed test

* More testing

* Revert "More testing"

This reverts commit 40304335c49d27f7024703da4f3ac4d775af52f7.

* Linting

* Support orphan projects

* Support orphan projects

* Fix filter

* Add a failing test

* "orphan" is an static attribute, always in effect

---------

Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2025-11-27 13:47:41 +08:00
Steven Taylor b957e17dd1 Support PREK_CONTAINER_RUNTIME=podman to override container runtime (#1033)
* feat: container runtime selection

use both docker and podman runtimes

1. if only docker on path use docker runtime
2. if only podman on path use podman runtime
3. to specify runtime use PREK_CONTAINER_RUNTIME

Signed-off-by: Steven Taylor <steven@taylormuff.co.uk>

* Tweak detection

---------

Signed-off-by: Steven Taylor <steven@taylormuff.co.uk>
Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2025-11-07 17:12:35 +08:00
Jo 476d84cf00 Fix PREK_UV_SOURCE list indentation (#977) 2025-10-27 17:34:12 +08:00
Steven Taylor 7161581362 Allow using system trusted store by PREK_NATIVE_TLS (#959) 2025-10-26 03:56:02 +08:00
Jo 17e3629be1 Update document (#809) 2025-09-28 17:08:11 +08:00
Jo 0ba14e2f1d Add support for specifying PREK_UV_SOURCE (#766)
* Add support for specifying `PREK_UV_SOURCE`

* Fix

* Improve

* debug

* Fix
2025-09-20 18:24:35 +08:00
Jo 65c29da7b6 Update some docs (#745)
* .

* Improve some docs
2025-09-15 15:59:13 +08:00
Jo cbddcb9fb6 Add docs about configuration (#703) 2025-09-10 15:45:52 +08:00