Skip to content

Commit 5672d54

Browse files
committed
Add docs on the prek hook system; Configure doctoc hook
1 parent 736554e commit 5672d54

2 files changed

Lines changed: 100 additions & 1 deletion

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ repos:
5858
- id: doctoc
5959
name: add TOC for Markdown files
6060
description: automatically keeps your table of contents up to date
61-
files: ^README\.md$
61+
files: ^(PREK|README)\.md$
6262
priority: 40
6363
- repo: https://github.com/codespell-project/codespell
6464
rev: 2ccb47ff45ad361a21071a7eedda4c37e6ae8c5a # frozen: v2.4.2

PREK.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Git Hook Management with `prek`
2+
3+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
4+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
5+
6+
- [1. Installation Methods](#1-installation-methods)
7+
- [Option A: Using Homebrew (macOS / Linux)](#option-a-using-homebrew-macos--linux)
8+
- [Option B: Using `uv`](#option-b-using-uv)
9+
- [Option C: Using `pipx`](#option-c-using-pipx)
10+
- [Option D: Direct Binary](#option-d-direct-binary)
11+
- [Option E: Install with pip](#option-e-install-with-pip)
12+
- [2. Basic CLI Usage](#2-basic-cli-usage)
13+
- [3. The `prek` Priority & Execution System](#3-the-prek-priority--execution-system)
14+
- [4. Tips for `prek`](#4-tips-for-prek)
15+
16+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
17+
18+
`prek` is a high-performance, ultra-fast Git hook manager written in Rust.
19+
It serves as a drop-in, dependency-free replacement for the standard Python `pre-commit` framework.
20+
By utilizing Rust's concurrency, sharing toolchains globally, and integrating with `uv` for environment management,
21+
`prek` drastically reduces installation times and cache footprints while natively interpreting your
22+
`.pre-commit-config.yaml` files.
23+
24+
---
25+
26+
## 1. Installation Methods
27+
28+
You can install `prek` using any of the following methods:
29+
30+
### Option A: Using Homebrew (macOS / Linux)
31+
32+
The most direct way to install `prek` is via Homebrew:
33+
34+
```shell
35+
brew install prek
36+
```
37+
38+
### Option B: Using `uv`
39+
40+
If you use `uv`, you can install it as a standalone tool:
41+
42+
```shell
43+
uv tool install prek
44+
```
45+
46+
### Option C: Using `pipx`
47+
48+
For an isolated Python-based binary environment installation:
49+
50+
```shell
51+
pipx install prek
52+
```
53+
54+
### Option D: Direct Binary
55+
56+
You can download pre-compiled execution assets directly from the prek GitHub Releases page.
57+
58+
### Option E: Install with pip
59+
60+
```shell
61+
pip install prek
62+
```
63+
64+
---
65+
66+
## 2. Basic CLI Usage
67+
68+
Manage your Git lifestyle checks using these essential commands:
69+
70+
* **Install Hooks**: Sets up the necessary Git hooks infrastructure inside your local workspace. Ensure you run this command directly from the root of your repository:
71+
`prek install`
72+
* **Run Hooks on Staged Files**: Automatically checks files currently staged in your index before committing.
73+
`prek run`
74+
* **Run Hooks on All Files**: Evaluates the full repository layout—ideal for initial setups or CI pipelines.
75+
`prek run --all-files`
76+
* **Run a Specific Hook**: Execute only one hook directly by appending its explicit identifier.
77+
`prek run <hook_id> --all-files`
78+
* **Uninstall Hooks**: Safely unregisters and removes the hooks path settings from your local Git workspace.
79+
`prek uninstall`
80+
81+
---
82+
83+
## 3. The `prek` Priority & Execution System
84+
85+
`prek` optimizes how your pipeline resolves rules by establishing a clear hierarchy:
86+
87+
1. **CLI Runtime Flags**: Command arguments provided explicitly (like `--files` or `--directory`) instantly override underlying configuration rules.
88+
2. **Built-in Native Overrides**: `prek` replaces common, resource-heavy Python hooks (like `trailing-whitespace`) with native Rust implementations. These run instantly with zero overhead, taking priority over traditional process invocation.
89+
3. **Workspace-Aware Scheduling**: In complex monorepos, `prek` dynamically discovers multi-project folders. Independent folders at identical file depths are processed concurrently to finish tasks faster without overlapping file scopes.
90+
4. **Strict File Extension Rules**: To keep validations accurate, file type discovery uses exact suffix matches. For instance, a file named `sample.pdf.txt` evaluates strictly as a text asset rather than tripping binary filters.
91+
92+
---
93+
94+
## 4. Tips for `prek`
95+
96+
* **Arrange Modifiers First**: Position hooks that actively alter files (such as code formatters and whitespace trimmers) above validation linters in your `.pre-commit-config.yaml`. This ensures checks validate finished formatting.
97+
* **Leverage `--dry-run**`: Test pattern match filters or complex configuration additions cleanly with `prek run --dry-run` to trace file targeting without executing changes.
98+
* **Cooling-off Periods for Safety**: Run `prek update --cooldown-days 7` to avoid downloading breaking changes instantly, keeping newly published upstream dependencies on hold for a week.
99+
* **CI Build Verification**: In automated jobs, run `prek update --check` to flag mismatching pins or frozen tags instantly without altering workspace configurations during execution.

0 commit comments

Comments
 (0)