Skip to content

Document hook_types flag and default_install_hook_types behavior#1225

Merged
j178 merged 3 commits intomasterfrom
copilot/fix-post-commit-hook
Dec 14, 2025
Merged

Document hook_types flag and default_install_hook_types behavior#1225
j178 merged 3 commits intomasterfrom
copilot/fix-post-commit-hook

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 14, 2025

The --hook-type / -t flag was undocumented, causing confusion about the difference between a hook's stages parameter (which stages a hook can run in) and --hook-type (which stages to actually install hooks for).

Changes

Added documentation to hook_types field in three structs:

  • InstallArgs: Clarifies that --hook-type specifies which git hook stages to install, defaults to default_install_hook_types from config or pre-commit
  • UninstallArgs: Same default behavior as install (was incorrectly assumed to uninstall all hook types)
  • InitTemplateDirArgs: Expanded minimal docs to match the other two

All three now explicitly mention:

  1. The difference from hook's stages parameter in config
  2. The default_install_hook_types config option
  3. The pre-commit fallback default

Generated CLI reference documentation updated automatically via the existing test infrastructure.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • mirrors.aliyun.com
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek /home/REDACTED/work/prek/prek/target/debug/prek install-hooks 7b012f.0lcsp62g3/usr/libexec/gcc/x86_64-linux-gnu/13/liblto_plugin.so 7b012f.0uunehm2k-plugin-opt=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper 7b01�� 7b012f.1thssvl7e--build-id 31e55646.0fnjq53--eh-frame-hdr 31e55646.0nkfynl-m 31e55646.0vpsks4bash 31e55646.0xn5yzf--norc 31e55646.13a4tkb--noprofile 31e55646.14zf254-dynamic-linker 31e5�� 31e55646.193qbus-pie 31e55646.1hruvxh-z 31e55646.1o4qxbqnow 31e55646.1oq6syn/usr/bin/git 31e55646.1re00to-c 31e55646.1ta1m7bcore.useBuiltinFSMonitor=false 31e55646.22ezco7rev-parse (dns block)
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek /home/REDACTED/work/prek/prek/target/debug/prek install-hooks --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -z now -fuse-ld=lld -z relro -o 3936�� ck6esr3x5olrhxooh9.0ugdsqx.rcgu.o w41wn4zm6cfbdux46l.0ugdsqx.rcgu.o b/rustlib/x86_64-m b/rustlib/x86_64/home/REDACTED/.rustup/toolchains/1.91-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/bin/gcc-ld/ld.lld b/rustlib/x86_64-plugin b/rustlib/x86_64/usr/libexec/gcc/x86_64-linux-gnu/13/liblto_plugin.so b/rustlib/x86_64-plugin-opt=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper (dns block)
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek /home/REDACTED/work/prek/prek/target/debug/prek install --install-hooks /home/REDACTED/work/prek/prek/target/debug/deps/auto_update-a359c9e39a37bed6 2lal�� own-linux-gnu/li/home/REDACTED/work/prek/prek/target/debug/deps/run-2042b33f0bbabeab.0cq0op0yf8m9ucc 0f3.087odwibys7b/home/REDACTED/work/prek/prek/target/debug/deps/run-2042b33f0bbabeab.0d8in8zt992r8-m64 b/rustlib/x86_64-REDACTED-linux-gnu/bin/gcc-ld/ld.lld 0f3.11cxv1yq5399/home/REDACTED/.rustup/toolchains/1.91-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_64/home/REDACTED/work/prek/prek/target/debug/deps/prek_pty-972eca60d2b6ee1d.5a0d272pxrfxpbyxibukkevjd.0h1zbzo.rcgu.o 0f3.1eaizeavdub9-flavor 0f3.289mu25m6xccgnu b/rustlib/x86_64-plugin 0f3.�� 0f3.2f2fidinkdyi-plugin-opt=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper 0f3.2hfveram42x2-plugin-opt=-fresolution=/tmp/ccdqy5QF.res 9be2e3dd6baf 0f3.2pv1443p4o2hbash 0f3.2s0yxl86sgf4--norc 0f3.39u1hvx4cb6v--noprofile 9be2e3dd6baf (dns block)
  • mirrors.cloud.tencent.com
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek /home/REDACTED/work/prek/prek/target/debug/prek install-hooks 7b012f.0lcsp62g3/usr/libexec/gcc/x86_64-linux-gnu/13/liblto_plugin.so 7b012f.0uunehm2k-plugin-opt=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper 7b01�� 7b012f.1thssvl7e--build-id 31e55646.0fnjq53--eh-frame-hdr 31e55646.0nkfynl-m 31e55646.0vpsks4bash 31e55646.0xn5yzf--norc 31e55646.13a4tkb--noprofile 31e55646.14zf254-dynamic-linker 31e5�� 31e55646.193qbus-pie 31e55646.1hruvxh-z 31e55646.1o4qxbqnow 31e55646.1oq6syn/usr/bin/git 31e55646.1re00to-c 31e55646.1ta1m7bcore.useBuiltinFSMonitor=false 31e55646.22ezco7rev-parse (dns block)
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek /home/REDACTED/work/prek/prek/target/debug/prek install-hooks --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -z now -fuse-ld=lld -z relro -o 3936�� ck6esr3x5olrhxooh9.0ugdsqx.rcgu.o w41wn4zm6cfbdux46l.0ugdsqx.rcgu.o b/rustlib/x86_64-m b/rustlib/x86_64/home/REDACTED/.rustup/toolchains/1.91-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/bin/gcc-ld/ld.lld b/rustlib/x86_64-plugin b/rustlib/x86_64/usr/libexec/gcc/x86_64-linux-gnu/13/liblto_plugin.so b/rustlib/x86_64-plugin-opt=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper (dns block)
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek /home/REDACTED/work/prek/prek/target/debug/prek install --install-hooks /home/REDACTED/work/prek/prek/target/debug/deps/auto_update-a359c9e39a37bed6 2lal�� own-linux-gnu/li/home/REDACTED/work/prek/prek/target/debug/deps/run-2042b33f0bbabeab.0cq0op0yf8m9ucc 0f3.087odwibys7b/home/REDACTED/work/prek/prek/target/debug/deps/run-2042b33f0bbabeab.0d8in8zt992r8-m64 b/rustlib/x86_64-REDACTED-linux-gnu/bin/gcc-ld/ld.lld 0f3.11cxv1yq5399/home/REDACTED/.rustup/toolchains/1.91-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_64/home/REDACTED/work/prek/prek/target/debug/deps/prek_pty-972eca60d2b6ee1d.5a0d272pxrfxpbyxibukkevjd.0h1zbzo.rcgu.o 0f3.1eaizeavdub9-flavor 0f3.289mu25m6xccgnu b/rustlib/x86_64-plugin 0f3.�� 0f3.2f2fidinkdyi-plugin-opt=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper 0f3.2hfveram42x2-plugin-opt=-fresolution=/tmp/ccdqy5QF.res 9be2e3dd6baf 0f3.2pv1443p4o2hbash 0f3.2s0yxl86sgf4--norc 0f3.39u1hvx4cb6v--noprofile 9be2e3dd6baf (dns block)
  • pypi.tuna.tsinghua.edu.cn
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek /home/REDACTED/work/prek/prek/target/debug/prek install-hooks 7b012f.0lcsp62g3/usr/libexec/gcc/x86_64-linux-gnu/13/liblto_plugin.so 7b012f.0uunehm2k-plugin-opt=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper 7b01�� 7b012f.1thssvl7e--build-id 31e55646.0fnjq53--eh-frame-hdr 31e55646.0nkfynl-m 31e55646.0vpsks4bash 31e55646.0xn5yzf--norc 31e55646.13a4tkb--noprofile 31e55646.14zf254-dynamic-linker 31e5�� 31e55646.193qbus-pie 31e55646.1hruvxh-z 31e55646.1o4qxbqnow 31e55646.1oq6syn/usr/bin/git 31e55646.1re00to-c 31e55646.1ta1m7bcore.useBuiltinFSMonitor=false 31e55646.22ezco7rev-parse (dns block)
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek /home/REDACTED/work/prek/prek/target/debug/prek install-hooks --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -z now -fuse-ld=lld -z relro -o 3936�� ck6esr3x5olrhxooh9.0ugdsqx.rcgu.o w41wn4zm6cfbdux46l.0ugdsqx.rcgu.o b/rustlib/x86_64-m b/rustlib/x86_64/home/REDACTED/.rustup/toolchains/1.91-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/bin/gcc-ld/ld.lld b/rustlib/x86_64-plugin b/rustlib/x86_64/usr/libexec/gcc/x86_64-linux-gnu/13/liblto_plugin.so b/rustlib/x86_64-plugin-opt=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper (dns block)
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek /home/REDACTED/work/prek/prek/target/debug/prek install --install-hooks /home/REDACTED/work/prek/prek/target/debug/deps/auto_update-a359c9e39a37bed6 2lal�� own-linux-gnu/li/home/REDACTED/work/prek/prek/target/debug/deps/run-2042b33f0bbabeab.0cq0op0yf8m9ucc 0f3.087odwibys7b/home/REDACTED/work/prek/prek/target/debug/deps/run-2042b33f0bbabeab.0d8in8zt992r8-m64 b/rustlib/x86_64-REDACTED-linux-gnu/bin/gcc-ld/ld.lld 0f3.11cxv1yq5399/home/REDACTED/.rustup/toolchains/1.91-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_64/home/REDACTED/work/prek/prek/target/debug/deps/prek_pty-972eca60d2b6ee1d.5a0d272pxrfxpbyxibukkevjd.0h1zbzo.rcgu.o 0f3.1eaizeavdub9-flavor 0f3.289mu25m6xccgnu b/rustlib/x86_64-plugin 0f3.�� 0f3.2f2fidinkdyi-plugin-opt=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper 0f3.2hfveram42x2-plugin-opt=-fresolution=/tmp/ccdqy5QF.res 9be2e3dd6baf 0f3.2pv1443p4o2hbash 0f3.2s0yxl86sgf4--norc 0f3.39u1hvx4cb6v--noprofile 9be2e3dd6baf (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>I set stages: [post-commit], but it still only generates a pre-commit hook?</issue_title>
<issue_description>### Summary

prek install
prek installed at `.git/hooks/pre-commit`

Platform

LinuxMint

Version

prek 0.2.22

.pre-commit-config.yaml

repos:
  - repo: local
    hooks:
      - id: php-cs-fixer
        name: PHP CS Fixer
        entry: ./vendor/bin/php-cs-fixer fix
        language: system
        files: \.php$
        types: [php]
        stages: [post-commit]

Log file

No response</issue_description>

<agent_instructions>Add docstring to hook_types flag of InstallArgs in crates/prek/src/cli/mod.rs</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@j178 Related https://github.com//issues/1160#issuecomment-3601804266 @j178 I just realized this flag isn’t documented. I’ll add that in—thanks for the heads‑up.

This behavior is inherited from the original pre-commit. The hook’s stages parameter tells you which stages a hook can run in. For example, the trailing‑whitespace hook in pre-commit-hooks says it can run in [pre-commit, pre-push, manual]. If a hook doesn’t specify anything, it means it can run in all stages.

On the other hand, the --hook-stage option in prek install tells it which stages you actually want the hook to run in.

These are two different concepts. If prek install were to install hooks based on the stages declared in the hook itself, then pretty much every stage hook would end up getting installed—which is usually not what most users want.

我也才发现这个参数没有文档说明,我会加一下,感谢提醒

这个行为是从原版 pre-commit 继承来的。hook 的 stages 参数是用来声明这个 hook 可以运行在哪些 stage 下,比如说 pre-commit-hooks 的 trailing-whitespace 声明自己可以运行在 [pre-commit, pre-push, manual] 下(不声明表示可以在所有 stage 下运行)。

prek install--hook-stage 是用来指定希望在哪些 stage 下运行 hook。

这两者是不同的概念,如果 prek install 默认按照 hook 声明的 stages 安装的话,基本上所有 stage hook 都会被安装了,反而不是大多数用户希望的效果。</comment_new>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits December 14, 2025 09:14
Co-authored-by: j178 <10510431+j178@users.noreply.github.com>
Co-authored-by: j178 <10510431+j178@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix post-commit hook generation in prek Document hook_types flag and default_install_hook_types behavior Dec 14, 2025
Copilot AI requested a review from j178 December 14, 2025 09:23
@codecov
Copy link
Copy Markdown

codecov bot commented Dec 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.81%. Comparing base (6d14524) to head (f2230a2).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1225   +/-   ##
=======================================
  Coverage   89.81%   89.81%           
=======================================
  Files          79       79           
  Lines       15274    15274           
=======================================
  Hits        13718    13718           
  Misses       1556     1556           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@j178 j178 marked this pull request as ready for review December 14, 2025 09:30
@j178 j178 merged commit a46ae58 into master Dec 14, 2025
31 of 39 checks passed
@j178 j178 deleted the copilot/fix-post-commit-hook branch December 14, 2025 09:35
@j178 j178 added the documentation Improvements or additions to documentation label Dec 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

I set stages: [post-commit], but it still only generates a pre-commit hook?

2 participants