Skip to content

Commit a423db5

Browse files
committed
fix(eql): make the pre-commit drift gate run in the monorepo
The hook never ran in cipherstash/stack, and would have matched nothing if it had: - `mise run install-hooks` set core.hooksPath to `tasks/githooks`. Git resolves a relative hooksPath against the root of the working tree, which here is the monorepo root, so git looked for `tasks/githooks` there and ran no hook. It now writes the path from the root, through `git rev-parse --show-prefix`. - Git runs a hook from the root of the working tree, so the staged paths carried a `packages/eql/` prefix that the hook's patterns, anchored at `crates/` and `src/`, never matched. The hook now lists only the staged paths under this package, relative to it. - `mise run` ran from the monorepo root, where this package's tasks are not defined. The hook now works from the package root. The prefix is computed from paths rather than with `cd` and `git diff --relative`, because git exports GIT_DIR to a hook, and with GIT_DIR set git takes the current directory as the top of the working tree. Checked with `git hook run pre-commit` from the monorepo root: a staged `src/v3/schema.sql` runs `test:schemas:parity`, and an unrelated staged file runs nothing. Running the hook from the package directory still works. Claude-Session: https://claude.ai/code/session_01VYKAWbd361xDLmqBdLoUcB
1 parent 8ead51c commit a423db5

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

‎packages/eql/mise.toml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ run = "bash tasks/schemas-parity.sh"
231231
[tasks."install-hooks"]
232232
description = "Point git at the committed hooks in tasks/githooks (run once per clone) so commits touching the catalog/generated surfaces are drift-gated locally"
233233
dir = "{{config_root}}"
234-
run = "git config core.hooksPath tasks/githooks"
234+
# Git resolves a relative core.hooksPath against the root of the working tree,
235+
# not this directory, so prefix the path from the root to this package.
236+
run = 'git config core.hooksPath "$(git rev-parse --show-prefix)tasks/githooks"'
235237

236238
[tasks."test:codegen"]
237239
description = "Run the encrypted-domain catalog + generator tests (no database required)"

‎packages/eql/tasks/githooks/pre-commit‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,24 @@
1313
# Unrelated commits skip the gate entirely, so this is a no-op for most commits.
1414
set -euo pipefail
1515

16-
staged=$(git diff --cached --name-only --diff-filter=ACMRD)
16+
# Git runs a hook from the root of the working tree. In cipherstash/stack that
17+
# is the monorepo root, not this package, so the staged paths carry a
18+
# `packages/eql/` prefix the patterns below would never match, and `mise run`
19+
# would not find this package's tasks. List only the staged paths under this
20+
# package, relative to it, then work from the package root.
21+
#
22+
# The prefix is worked out from paths, not with `cd` and `git diff --relative`:
23+
# git exports GIT_DIR to a hook, and with GIT_DIR set and no GIT_WORK_TREE, git
24+
# takes the current directory as the top of the working tree, so after a `cd`
25+
# `--relative` strips nothing.
26+
package=$(cd "$(dirname "$0")/../.." && pwd -P)
27+
top=$(cd "$(git rev-parse --show-toplevel)" && pwd -P)
28+
relative=()
29+
if [ "$package" != "$top" ]; then
30+
relative=("--relative=${package#"$top"/}/")
31+
fi
32+
staged=$(git diff --cached --name-only "${relative[@]}" --diff-filter=ACMRD)
33+
cd "$package"
1734

1835
if echo "$staged" | grep -Eq '^(crates/eql-domains/|crates/eql-codegen/|src/v3/scalars/|crates/eql-bindings/src/v3/|crates/eql-bindings/src/v4/|crates/eql-bindings/bindings/|crates/eql-bindings/schema/)'; then
1936
echo "pre-commit: catalog/generator/generated surface touched — verifying freshness…"

0 commit comments

Comments
 (0)