1
0
mirror of https://github.com/j178/prek.git synced 2026-04-03 17:34:03 +02:00
Commit Graph

109 Commits

Author SHA1 Message Date
Jo
8436843c0f Update script.rs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-01-27 15:50:16 +08:00
Jo
d79b8d514f Add comments 2026-01-27 15:50:16 +08:00
Jo
1e05049090 Add tests 2026-01-27 15:50:16 +08:00
Jo
e9962a656a Improve 2026-01-27 15:50:16 +08:00
Jo
5923351f69 Add tests 2026-01-27 15:50:16 +08:00
Jo
2957d6d747 Support inline script for language: script 2026-01-27 15:50:16 +08:00
Jo
bb8a1b4998 Use hint: consistently (#1482) 2026-01-27 15:18:19 +08:00
Jo
755e48765b Simplify integration tests (#1475) 2026-01-25 14:58:18 +08:00
Shaan Majid
077753f54f test: add git_cmd helper to disable GPG signing in tests (#1473)
Introduces a centralized `git_cmd()` helper that disables GPG signing
via environment variables, preventing test failures for contributors
with signing enabled globally. Refactors all test files to use the
helper, reducing boilerplate.

@j178 lmk if you disagree with this and want me to close this haha, but
I was getting kind of annoyed at all the prompts from my password
manager asking me to sign commits whenever running the unit test suite
locally lol

---------

Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2026-01-25 12:13:08 +08:00
tison
395ae4ba0c Replace tokio::sync with mea primitives (#1467)
Signed-off-by: tison <wander4096@gmail.com>
2026-01-24 11:42:17 +08:00
Shaan Majid
e4d3dfd10a Add language: swift support (#1463)
* feat(swift): add Swift language support

Implement Swift language support for prek:
- Query swift executable and parse version from `swift --version`
- Handle both macOS (Apple Swift) and Linux version formats
- Normalize versions without patch component (e.g., "6.1" -> "6.1.0")
- Handle pre-release versions (e.g., "6.2-dev")
- Build Package.swift repos with `swift build -c release`
- Use `swift build --show-bin-path` to resolve target-specific bin directory
- Add built binaries to PATH when running hooks
- Health check verifies swift executable still exists

Include unit tests for version parsing covering:
- macOS format with swift-driver prefix
- Linux format
- Multiline output handling
- Versions without patch component
- Development/nightly versions
- Invalid input handling

* test(swift): add Swift language tests

* docs(swift): mark Swift as supported in language documentation

* ci: stabilize swift toolchain setup across platforms

- pin Swift version in env to keep CI deterministic\n- use SwiftyLab/setup-swift on Windows where swift-actions fails\n- install Swift on macOS and reset TOOLCHAINS back to Xcode\n- force CC/CXX/SDKROOT from Xcode so Ruby native gems compile\n\nThis keeps Swift hooks available while restoring Xcode's clang/SDK,\nwhich avoids msgpack native extension failures on macOS.
2026-01-23 11:28:18 +08:00
Jo
eee6fc3cd5 Extract go version constraint from go.mod (#1457) 2026-01-22 18:00:20 +08:00
Jo
2a7d898a9c Bump uv versions 2026-01-22 14:32:20 +08:00
Jo
720c7cb732 Use git ls-remote --tags to list bun versions (#1439) 2026-01-22 11:05:41 +08:00
Jo
7d4ebbdb27 Bootstrap config-tracking.json only when it is not exist (#1437) 2026-01-22 11:05:41 +08:00
Jo
34c1609b6e Fix unused tool versions not removed in prek cache gc (#1436) 2026-01-22 11:05:41 +08:00
Jo
c34c41e384 Set GITHUB_TOKEN when running tests (#1426) 2026-01-22 11:05:41 +08:00
Jo
013a8ae9f5 Add more tests for prek cache gc (#1425) 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
Jo
c30dbb8490 prek cache gc remove specific unused tool versions (#1422) 2026-01-22 11:05:41 +08:00
Jo
5db9e473d1 Show accurate repo and hook details in prek cache gc -v (#1420)
* .

* Show accurate repo and hook details in `prek cache gc -v`
2026-01-22 11:05:41 +08:00
Jo
96aab7ec76 Show total size prek cache gc removed (#1418)
* Show total size `prek cache gc` removed

* Tweak
2026-01-22 11:05:41 +08:00
Jo
b6371ac534 Bootstrap tracking configs from workspace cache (#1417) 2026-01-22 11:05:41 +08:00
Jo
e67fb2bf3f Implement prek cache gc (#1410)
* Implement `prek cache gc`

* Refactor

* Improve

* Add `--dry-run`

* Add color

* Add `--verbose`

* Improve styling

* Update docs

* Fix

* Improve

* Refactor

* Add test

* Minor
# Conflicts:
#	crates/prek/src/store.rs
2026-01-22 11:05:41 +08:00
Shaan Majid
886547fd01 Resolve relative repo paths from config file directory (#1443)
* fix: resolve relative repo paths from config file directory

Relative paths like `../hook-repo` in `.pre-commit-config.yaml` were
being resolved against the process's current working directory instead
of the directory containing the config file. This broke configs in
subprojects that used relative paths to hook repositories.

The fix resolves relative repo paths in `Project::from_config_file`
right after loading the config, using the config file's parent
directory as the base.

Fixes #1065

* Minor tweaks

---------

Co-authored-by: Jo <10510431+j178@users.noreply.github.com>
2026-01-22 11:05:19 +08:00
Jules Tamagnan
1ea64fcb4a Support refs to trees (#1449)
* Support refs to trees

* Add test

* Add fallback

* style

* fixup
2026-01-22 11:00:12 +08:00
Shaan Majid
41e2b73246 test: add integration tests for hook skip behavior (#1428)
Add integration tests verifying that prek correctly identifies and
reports skipped hooks in various scenarios.

Tests cover:
- All hooks skipped due to no matching files
- Dry run mode skipping all hooks
- Mixed scenarios with both executed and skipped hooks
- Skipped hooks across multiple priority groups

Includes regression test for #1335: verifies that `git diff` is only
called once (initial baseline) when all hooks skip, not once per
priority group. Uses tracing output to count `get_diff` calls.

Refs: #1327, #1335
2026-01-22 10:46:34 +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
edcf3d82ab Add taplo-fmt prek hook to format toml files (#1435) 2026-01-21 14:52:53 +08:00
tison
c8091b298f Migrate from uv-once-map to mea OnceMap (#1433)
Signed-off-by: tison <wander4096@gmail.com>
2026-01-21 13:57:20 +08:00
Jo
4dfb3fd830 Improve JSON schema for repo field (#1432) 2026-01-21 11:45:39 +08:00
Jo
23b4456a80 Expand ~ tilde in PREK_HOME (#1431) 2026-01-21 11:35:52 +08:00
Jo
c0bcc788de Improve generated JSON schema for builtin and meta hooks (#1427)
* Improve generated JSON schema for builtin and meta hooks

* Improve JSON schema for builtin and meta hooks
2026-01-21 01:08:17 +08:00
Shaan Majid
dcf2c5aff1 Use split() instead of resolve(None) for builtin hook argument parsing (#1415)
* fix: use split() instead of resolve(None) for builtin hook argument parsing

Builtin hooks were calling `hook.entry.resolve(None)` to get arguments
for clap parsing. After commit 85448ac, `resolve(None)` falls back to
system PATH, which can find system-wide binaries (e.g., from
`pip install pre-commit-hooks`), parse their shebangs, and corrupt
argument parsing.

The fix changes these 6 builtin hooks to use `split()` instead, which
just tokenizes the entry string without PATH resolution - exactly what's
needed for argument parsing.

Fixes #1412

* test: add regression test for builtin hooks with system PATH binaries

Adds a test that verifies builtin hooks work correctly even when
system-wide binaries with matching names exist on PATH (e.g., from
`pip install pre-commit-hooks`).

The test creates a fake `trailing-whitespace-fixer` binary with a
shebang in a temp directory, adds it to PATH, and verifies the builtin
trailing-whitespace hook still works correctly.
2026-01-20 05:27:26 +08:00
Jo
f1b110c0a8 Add tests for yaml::merge_keys (#1409) 2026-01-19 18:47:27 +08:00
Jo
1988af24b3 Add two test cases for unknown hook id (#1408) 2026-01-19 18:09:41 +08:00
Jo
63a9c5c8f8 Refactor config layout (#1407)
* Refactor config layout

* Fix

* Add a test

* Tweak
2026-01-19 17:54:01 +08:00
Jo
e9716ae31b Avoid file lock warning for in-process contention (#1406)
* .

* Avoid file lock warning for in-process contention
2026-01-19 15:00:51 +08:00
Jo
dfbea266fd Remove #[cfg(unix)] gate on generating cli reference (#1402)
* Remove `#[cfg(unix)]` gate on generating cli reference

* Tweak

* Debug

* Debug

* Normalized eol

* Debug

* Add gitattributes

* Final
2026-01-19 13:37:34 +08:00
Jo
ac1b1d4202 Add --stage as an alias for --hook-stage (#1398) 2026-01-18 22:37:42 +08:00
Jo
8faa42c091 Add nextest partitioning for Windows tests (#1389)
* Add nextest partitioning for Windows tests

* Fix

* Fix

* Fix

* Fix

* Disable optimize for fast-build

* Fix integration bin name

* Fix

* Fix

* Try fix

* Debug

* Fix

* Fix path substitute

* Fix
2026-01-18 20:37:53 +08:00
Jo
c67ac0ea29 Make CURRENT_REPORTER a Weak<ProgressReporter> (#1390) 2026-01-18 16:58:08 +08:00
Jo
4a8b58b7a7 Show warning if file lock acquiring blocks for long time (#1353)
* Show a lock acquire warning if it blocks

* Improve

* Add test
2026-01-18 16:24:45 +08:00
Jo
845d849719 Speed up reuse_env test case (#1388)
Replace `flake8` with a local package to reduce install time.
2026-01-18 14:53:39 +08:00
Jo
a58828ca4c Check for duplicate keys in check-json5 builtin hook (#1387) 2026-01-18 14:27:07 +08:00
Jo
0e934c383c Do not resolve entry for docker_image (#1386) 2026-01-18 14:04:39 +08:00
Jo
85448ac471 Fix command lookup on Windows (#1383)
* Add a failing test

* Fix

* Docker entry should not be resolved
2026-01-17 22:53:13 +08:00
Jo
414d0cc088 Singleflight Python health checks with cached interpreter info (#1381) 2026-01-17 19:08:02 +08:00
Jo
340a773f90 Preserve quoting style in auto-update (#1379) 2026-01-17 17:28:18 +08:00
Jo
f6731ad435 Explain project configuration scope (#1373) 2026-01-16 19:09:44 +08:00