Skip to content

fix(hooks): check the whole codebase as staged in pre-commit - #303

Merged
paustint merged 2 commits into
mainfrom
fix/pre-commit-index-snapshot
Oct 16, 2026
Merged

paustint merged 2 commits into
mainfrom
fix/pre-commit-index-snapshot

Conversation

@paustint

@paustint paustint commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • The pre-commit hook now checks a snapshot of the index across the whole codebase. It used to pass staged paths to oxfmt and oxlint, which then read the working tree, so a file formatted on disk but never re-staged could slip through and unstaged edits could block a clean commit. commit -a and commit <path> are covered too, because git points GIT_INDEX_FILE at the right index.
  • The hook header now names all four repos that share it, so every copy is byte-identical. This mirrors chore: adopt oxfmt and oxlint with a pre-commit hook simple-xml#19.
  • checkout-index runs with --ignore-skip-worktree-bits, so files hidden by a sparse checkout or git update-index --skip-worktree are checked too. simple-xml gets the same change in fix(hooks): export skip-worktree entries into the pre-commit snapshot simple-xml#20, which keeps all four copies byte-identical.
  • AGENTS.md describes the new behavior.

No CHANGELOG entry, since nothing under src/ changed.

Test plan

  • Hook passes on a clean index, matching npm run format:check and npm run lint
  • Hook blocks an unformatted file staged under src/
  • Hook blocks a staged, unformatted file marked skip-worktree and removed from disk
  • Hook removes its temporary snapshot afterwards

The hook passed staged paths to oxfmt and oxlint, which read the working tree. A file formatted on disk but never re-staged could slip through, and unstaged edits could block a clean commit. It now exports the index to a temporary directory and checks every tracked file there, so it sees exactly what the commit will contain. The header names all four repos sharing the hook, so every copy is byte-identical.
Copilot AI balanced review requested due to automatic review settings October 10, 2026 16:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused hook and documentation changes correctly implement the stated staged-snapshot behavior.

0 open findings

What changed in this PR

Updates the pre-commit hook to validate the exact staged repository snapshot.

Changes:

  • Checks formatting and linting across the staged codebase.
  • Preserves unstaged working-tree changes.
  • Documents the revised hook behavior.
File Description
.githooks/​pre-commit Creates, checks, and cleans up an index snapshot.
AGENTS.md Documents whole-codebase staged validation.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

A relative TMPDIR prevents temporary snapshot cleanup.

0 open findings

Previously missed (1)

In code that hasn't changed since last review

Medium severity Relative TMPDIR causes snapshot cleanup to fail

.githooks/​pre-commit:31

If TMPDIR is relative, mktemp returns a relative path. After the hook changes into that directory, the EXIT trap resolves the path relative to the snapshot itself and fails to remove it, leaving a full source snapshot behind. Normalize the path before installing the trap.

🧠 Review effort: Balanced

@paustint

Copy link
Copy Markdown
Collaborator Author

Went through Copilot's previously-missed comment and it was valid:

  • .githooks/pre-commit:31 — fixed (lands with the next push). A relative TMPDIR gave a relative snapshot path that the EXIT trap resolved from inside the snapshot after the cd, leaking the whole snapshot. The path is now anchored to the hook's working directory before the trap is installed. Verified cleanup with relative, absolute and unset TMPDIR.

Also anchor a relative TMPDIR to the hook's working directory before
installing the EXIT trap, which otherwise resolved the path from
inside the snapshot after the cd and left the snapshot behind.
Copilot AI balanced review requested due to automatic review settings October 16, 2026 12:52
@paustint
paustint force-pushed the fix/pre-commit-index-snapshot branch from e7477ab to 449ed9b Compare October 16, 2026 12:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The snapshot handling, cleanup, and documentation are consistent, with no unresolved findings.

0 open findings

🧠 Review effort: Balanced

@paustint
paustint merged commit 2e1ebe1 into main Oct 16, 2026
10 checks passed
@paustint
paustint deleted the fix/pre-commit-index-snapshot branch October 16, 2026 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants