Repository navigation
refactor(dev-tools): consolidate git hook scripts under contrib/dev-tools/git - #1704
Conversation
…ools/git Move scripts/ content to canonical locations: - scripts/install-git-hooks.sh → contrib/dev-tools/git/install-git-hooks.sh - scripts/pre-commit.sh → deleted (duplicate) - contrib/dev-tools/git/hooks/pre-commit.sh → rewritten in new structured style - contrib/dev-tools/git/hooks/pre-push.sh → rewritten in new structured style The new pre-commit.sh uses a STEPS array with per-step timing and PASSED/FAILED output. It excludes nightly toolchain checks and e2e tests (too slow for pre-commit; covered by CI and pre-push). The new pre-push.sh follows the same structured style and retains all checks from the old script including nightly fmt/check/doc and e2e tests. Update all references across agents, skills, workflows, and documentation.
There was a problem hiding this comment.
Pull request overview
This PR consolidates git-hook related developer tooling by removing the old scripts/ entrypoints and standardizing on the canonical location under contrib/dev-tools/git/, while updating all internal documentation/workflow references accordingly.
Changes:
- Delete the duplicate
scripts/pre-commit.shand migrate callers tocontrib/dev-tools/git/hooks/pre-commit.sh. - Move/standardize the hook installer to
contrib/dev-tools/git/install-git-hooks.sh. - Rewrite
pre-commit.shandpre-push.shhook scripts into a structured “timed steps” format, and update docs/skills/agents/workflows to reference the new paths.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| scripts/pre-commit.sh | Removes the legacy/duplicate pre-commit entrypoint. |
| contrib/dev-tools/git/install-git-hooks.sh | Canonical git hook installer path and updated usage comment. |
| contrib/dev-tools/git/hooks/pre-commit.sh | Canonical structured pre-commit hook script. |
| contrib/dev-tools/git/hooks/pre-push.sh | Canonical structured pre-push hook script (nightly + e2e). |
| .githooks/pre-commit | Updates wrapper to call canonical pre-commit script under contrib/. |
| AGENTS.md | Updates hook/script paths in repo guidance. |
| docs/issues/1697-ai-agent-configuration.md | Updates referenced hook install + pre-commit invocation paths. |
| .github/workflows/copilot-setup-steps.yml | Updates workflow path filters and install command to new locations. |
| .github/agents/committer.agent.md | Updates “pre-commit validation command” path. |
| .github/agents/implementer.agent.md | Updates “pre-commit validation command” path. |
| .github/skills/dev/git-workflow/commit-changes/SKILL.md | Updates hook installation and pre-commit command references. |
| .github/skills/dev/git-workflow/run-pre-commit-checks/SKILL.md | Updates hook installation and pre-commit command references. |
| .github/skills/dev/maintenance/setup-dev-environment/SKILL.md | Updates hook installation and pre-commit command references. |
| .github/skills/dev/maintenance/update-dependencies/SKILL.md | Updates verification command reference to canonical pre-commit script. |
Comments suppressed due to low confidence (1)
contrib/dev-tools/git/install-git-hooks.sh:8
- This installer copies hook wrappers from
.githooks/into.git/hooks/, but the repo currently only contains.githooks/pre-commit. As a result, the canonicalcontrib/dev-tools/git/hooks/pre-push.shscript will not be installed as a Gitpre-pushhook and won’t run automatically. Consider adding a.githooks/pre-pushwrapper (like.githooks/pre-commit) or otherwise wiringpre-pushinto the installation process.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1704 +/- ##
========================================
Coverage 86.43% 86.43%
========================================
Files 288 288
Lines 22672 22672
Branches 22672 22672
========================================
+ Hits 19596 19597 +1
Misses 2838 2838
+ Partials 238 237 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- AGENTS.md: clarify nightly toolchain is also needed for pre-push checks - pre-push.sh: explicitly use cargo +stable for non-nightly steps to ensure consistent results across machines regardless of default toolchain
|
ACK b3d1e6b |
da2ce7
left a comment
There was a problem hiding this comment.
This is a post-merge review of #1704 as it stands at e170b9620 on the default branch.
What still runs from it is the runner skeleton shared by contrib/dev-tools/git/hooks/pre-commit.sh and contrib/dev-tools/git/hooks/pre-push.sh (the STEPS array, format_time, per-step timing, the main loop and the result banners), the installer at its new path contrib/dev-tools/git/install-git-hooks.sh, and the path filters and install step in .github/workflows/copilot-setup-steps.yml. The step lists, the command runner, the failure handling and the body of the .githooks/pre-commit dispatcher were rewritten afterwards, mostly in #1783. Two points of the merged state are now history: at d51ef2988 .githooks/ held only pre-commit, so the nightly checks the description calls "covered by CI and pre-push" ran locally only when pre-push.sh was started by hand, until d2d142049 added the pre-push dispatcher; and the word-splitting command runner and the relative E2E configuration path have since been replaced or removed.
[Minor] contrib/dev-tools/git/install-git-hooks.sh:15 resolves the destination with git rev-parse --git-path hooks, which honours core.hooksPath. For a developer whose global configuration points core.hooksPath at a shared directory, line 29 copies this repository's pre-commit and pre-push dispatchers into that directory, replacing the hooks already there without a backup; every other repository using that directory then runs a dispatcher that executes $repo_root/contrib/dev-tools/git/hooks/pre-commit.sh, which does not exist there, so its commits and pushes fail. Line 32 still prints → .git/hooks/<name> and the script exits 0. With core.hooksPath=.githooks the copy lands on the file itself and the script stops with "are the same file". Both cases reproduce with git 2.55.0 against a scratch repository. Smallest fix: stop with an explanatory error when git config --get core.hooksPath returns a value, refuse to overwrite an existing hook whose content differs, and print the resolved ${dest} instead of a fixed .git/hooks path.
[Minor] .github/workflows/copilot-setup-steps.yml:13 and :18 trigger the workflow on changes to contrib/dev-tools/git/hooks/pre-commit.sh, but the job never runs that script: line 55 installs the dispatchers and line 58 runs linter all. The environment it provisions has only the stable toolchain (line 37), while the hooks it installs run cargo +nightly fmt --all -- --check (contrib/dev-tools/git/hooks/pre-commit.sh:61, added in bed1a4d77) and the nightly fmt, check and doc commands at contrib/dev-tools/git/hooks/pre-push.sh:46-50. bed1a4d77 changed a listed path, so it triggered this workflow, which contained nothing that could fail on the new check; a commit made in the provisioned environment fails at that check unless nightly is fetched on demand. The filters also omit .githooks/**, the files line 55 actually copies, so a change to a dispatcher does not run the workflow at all. Smallest fix: install the nightly toolchain with its rustfmt component, run ./contrib/dev-tools/git/hooks/pre-commit.sh --format=json as the smoke check so the trigger tests what it lists, and add .githooks/** to both path filters.
[Minor] contrib/dev-tools/git/hooks/pre-commit.sh:210-217 reserves a log name with mktemp and then renames it to ${_tmp}.log, a name nothing reserved, without checking the rename. The script runs without set -e (line 22), so a failed mv is ignored and run_command writes to ${_tmp}.log through a plain > redirect (line 192), which follows a symbolic link. With the default log directory /tmp (line 70), which applies whenever the script is run directly as AGENTS.md describes, another local user watching /tmp can create <name>.log as a link between the two calls: the rename then fails in the sticky directory and the check's output truncates and overwrites the link's target on systems that do not restrict following links in sticky directories (macOS; Linux with fs.protected_symlinks=0), while on a default Linux system the check fails spuriously instead. The same lines are at contrib/dev-tools/git/hooks/pre-push.sh:199-206; both came in with a916d0bb1. Smallest fix: use the mktemp path itself as the log path and drop the rename, or create one private directory per run with mktemp -d and write the logs inside it; at the least, mv -- "$_tmp" "$log_path" || return 2.
[Nit] The two scripts that #1704 shaped from one template have drifted on their result contract under the same "schema_version": 1. On a failing check contrib/dev-tools/git/hooks/pre-commit.sh:378-391 puts the command's own status into the JSON exit_code and exits with it (a failing cargo test gives 101), while contrib/dev-tools/git/hooks/pre-push.sh:365-380 maps every failure to 1 or 2, so a check that itself exits 2 is reported there as an infrastructure error. A consumer of the JSON output cannot read exit_code the same way for both hooks, and the duplicated runner invites the next divergence. Smallest fix: choose one contract and move the shared runner into one file that both hooks source.
[Nit] contrib/dev-tools/git/hooks/pre-commit.sh:52 and :63 run ./contrib/dev-tools/checks/... by a path relative to the working directory, and neither hook script changes to the repository root. Started from a subdirectory (for example ../contrib/dev-tools/git/hooks/pre-commit.sh from packages/), the first check exits 127 with "No such file or directory" before anything else runs. Git runs hooks from the top level, so only direct invocation is affected. Smallest fix: cd "$(git rev-parse --show-toplevel)" after ensure_cargo_on_path in both scripts.
[Nit] .github/workflows/copilot-setup-steps.yml:49 installs cargo-machete unversioned and without --locked, while lines 46 and 52 pin [email protected] and [email protected] with --locked, so each run builds whatever release and dependency resolution the registry serves that day into the environment where the hooks then run cargo machete --with-metadata. The line predates #1704. Smallest fix: cargo install --locked cargo-machete@<version>.
Checked and found sound: no reference to the removed scripts/ paths remains at the pull request's head; the workflow keeps permissions: contents: read and uses no secrets and no pull_request_target; the dispatchers and the installer quote every path they use; .tmp/, where the dispatchers send hook logs, is git-ignored; format_time, the IFS='|' step parsing and the per-step timing behave correctly for the current step lists; the $? read in the else branch of pre-commit.sh and the PIPESTATUS[0] read after tee both capture the intended status; and json_escape removes or escapes every control character JSON forbids.
Summary
Consolidates the duplicate/misplaced scripts from
scripts/into their canonical location undercontrib/dev-tools/git/.Changes
Files moved / deleted
scripts/install-git-hooks.sh→contrib/dev-tools/git/install-git-hooks.shscripts/pre-commit.sh→ deleted (duplicate; canonical version now lives in hooks dir)Scripts rewritten in new structured style
Both hook scripts now use a
STEPSarray with per-step timing and clearPASSED/FAILEDoutput, matching the style of the newpre-commit.sh.contrib/dev-tools/git/hooks/pre-commit.sh(fast, ~3 min):cargo machete— unused dependency checklinter all— all linterscargo test --doc --workspace— documentation testscargo test --tests --benches --examples --workspace --all-targets --all-features— all testsNightly toolchain checks and e2e tests are intentionally excluded — they are too slow for pre-commit and are covered by CI and
pre-push.contrib/dev-tools/git/hooks/pre-push.sh(comprehensive, ~15 min):cargo machetelinter allcargo +nightly fmt --checkcargo +nightly check …cargo +nightly doc …cargo test --doc --workspacecargo test … --all-targets --all-featurese2e_tests_runner)References updated
All references to the old
scripts/paths have been updated across:.githooks/pre-commitAGENTS.md.github/workflows/copilot-setup-steps.yml.github/agents/committer.agent.md.github/agents/implementer.agent.md.github/skills/dev/git-workflow/commit-changes/SKILL.md.github/skills/dev/git-workflow/run-pre-commit-checks/SKILL.md.github/skills/dev/maintenance/setup-dev-environment/SKILL.md.github/skills/dev/maintenance/update-dependencies/SKILL.mddocs/issues/1697-ai-agent-configuration.md