Switch to prek rather than pre-commit (#7244)

This provides a native harness with several advantages over
`pre-commit`:

- Faster when initializing the cache
- Smaller cache sizes: under 43mb compared to over 62mb
- Better integration with `uv` for Python usage

Steps for migrating for existing contributors:

1.  Install `prek` following instructions in the updated docs.

2.  Replace hooks in an existing checkout with a special flag:

    ```sh
    prek install --overwrite
    ```

    The `--overwrite` flag is what removes the old hooks.

    If you used the pre-push variant:

    ```sh
    prek install --hook-type pre-push --overwrite
    ```

3.  Optional cleanups:

    ```sh
    rm -rf ~/.cache/pre-commit  # reclaim the old hook-environment cache
pipx uninstall pre-commit # if installed via pipx; or `brew uninstall
pre-commit`
    ```

Assisted-by: Antigravity with Gemini
This commit is contained in:
Chandler Carruth
2026-06-03 19:19:49 +00:00
committed by GitHub
parent 358df53c48
commit 76dd872ab4
12 changed files with 66 additions and 61 deletions
+4 -4
View File
@@ -171,7 +171,7 @@ def main() -> None:
else:
git_bin = _find_tool("git")
jj_bin = None
precommit_bin = _find_tool("pre-commit")
prek_bin = _find_tool("prek")
# Verify there are no uncommitted changes (jj has no equivalent).
if git_bin:
@@ -263,11 +263,11 @@ def main() -> None:
with open(final_path, "w") as final_file:
final_file.write(content)
# Run pre-commit for a ToC update, then push the PR update.
# Run prek for a ToC update, then push the PR update.
final_desc = "Filling out template with PR %d" % pr_num
if git_bin:
_run([git_bin, "add", temp_path, final_path])
_run([precommit_bin, "run"], check=False)
_run([prek_bin, "run"], check=False)
_run([git_bin, "commit", "--amend", "-m", final_desc])
_run([git_bin, "push", "--force-with-lease"])
@@ -275,7 +275,7 @@ def main() -> None:
assert jj_bin # For mypy.
_run(
[precommit_bin, "run", "--files", "$(jj diff --name-only)"],
[prek_bin, "run", "--files", "$(jj diff --name-only)"],
check=False,
)
_run([jj_bin, "describe", "-m", final_desc])