Repository navigation
fix(hooks): turn off config-driven commands on the git ignore checks hooks run - #17104
Conversation
…hooks run A git check-ignore reads the index, which starts the command a repository's core.fsmonitor names. The new hook::git_untrusted helper in lib/hook-utils.sh runs git with --no-pager -c core.fsmonitor=false -c core.hooksPath=/dev/null, which outrank the repository's config and its includes. Three ignore checks now go through it: - hook::file_is_gitignored (lib/hook-utils.sh and its 22 synced copies), which the format hooks call through hook::gitignored_out_of_scope; - spd_gitignored in guardrails' secret-pattern-detection (secret_pattern_detection_skip_gitignored, off by default); - hardcoded-path-check's ignore check against CLAUDE_PROJECT_DIR. Each suite plants core.fsmonitor in a fixture repository, shows plain git check-ignore runs it, and shows the hook's check does not. lib/resolve-convention-pattern.sh is unchanged: it is POSIX sh, so it cannot use the helper, and its git ls-files calls read the index before its ignore check does. Refs: #16959 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VcupokBnD3fgV5DKj7GeJA
The include file written by printf held the bash-form /tmp path, which the shell converts only in arguments, and the include overrides the converted value in .git/config, so Git for Windows could not run the planted hook and the fixture's proof would fail there. The include now names the hook in cygpath -m form where cygpath exists, as the block-main-checkout-edit suite does. Refs: #16959 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VcupokBnD3fgV5DKj7GeJA
|
Owned by the hub session Plugin Presets; it watches checks and review threads and merges. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
claude-security-review reviewed Security review: no security issues foundThis change makes hooks safer. It adds
What I checked:
Two gaps the PR description already states, neither added by this diff:
The review was not blocking only: this lane had not reviewed an earlier head. critical-findings: 0 |
|
claude-review reviewed Code review: PR #17104, no findingsThe PR adds one shared helper,
What I checked:
Closing issue: the PR says Loosened-check verdict: fail (default; the wrapper gave no verdict or patterns line); patterns: 0. The diff adds assertions and loosens no check. Spend: none; the change runs no paid or billed resource. Verifier dropped 0 of 0 candidates. |
#17104 added hook::git_untrusted for the three ignore checks. Drop this branch's HOOK_GIT array, and the array the merge from main left beside the function, and call the function at the remaining hook git call sites. Sites a bash function cannot reach without an extra process or at all (a `( … )` subshell or pipeline tail, an exec'd argv, `command git`, POSIX sh, Node, a library sourced without hook-utils.sh) write the same overrides out. block-dangerous-git's width probe and the hardcoded-path-check and temp-scratch probes used `$(exec git … 2>…)` for one process; a function cannot be exec'd, so the width probe runs `exec 2>&1` first inside the substitution and the other two put the redirect on a group around the assignment: one clone each under strace, as before. The comments that explained the old `exec` are removed. Trim lib/hook-git.test.sh to the sites #17104's tests do not cover, and reword the 22 fragments to what this branch adds. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Refs: #16959
Summary
git check-ignorereads the index, which starts the command a repository'score.fsmonitornames. The git ignore checks that hooks run now go through one shared helper,
hook::git_untrustedinlib/hook-utils.sh. It passes the overrides PR #16954 uses(
--no-pager -c core.fsmonitor=false -c core.hooksPath=/dev/null), which outrank the repository'sconfig and its includes.
Fix
The changed hooks, which run in every session that has these plugins:
hook::file_is_gitignoredinlib/hook-utils.shand its 22 synced copies. The format hooksand the other carriers call it through
hook::gitignored_out_of_scope.secret-pattern-detection:spd_gitignored, which runs only withsecret_pattern_detection_skip_gitignoredon (off by default).hardcoded-path-check: its ignore check againstCLAUDE_PROJECT_DIR.No other git call changes.
block-main-checkout-editalready passes these overrides through itsown
mce::git_exec. A patch changelog fragment was added for each of the 22 plugins that carryhook-utils.sh.Verification
core.fsmonitoris planted in a fixture repository. A plaingit check-ignoreis shown to run it, then the hook's check runs, returns the right answer, andthe marker file stays absent.
bash lib/hook-utils.test.sh: PASS=714 FAIL=0. Its fixture writes the planted hook's path incygpath -mform where cygpath exists. The same fix made the fixture fire under Git for Windowson PR ci(guardrails): run the main-checkout edit guard's suite in Windows CI #17073, where the bash-form path in an include file did not.
bash plugins/guardrails/hooks/secret-pattern-detection.test.sh: PASS=315 FAIL=0.bash plugins/guardrails/hooks/hardcoded-path-check.test.sh: PASS=173 FAIL=0.scripts/sync-shared-copies.shsynced the copies;check-changelog-fragments.sh --checkpasses;
shellcheck -xis clean; the pre-pushcheck-affectedpassed.hook::file_is_gitignored, whichlib/hook-utils.test.shcovers, and CI runs them.Not delivered
not create. This PR covers the git ignore checks, as the issue title says. Other hook git calls
that read the index are unchanged.
lib/resolve-convention-pattern.sh(and its guardrails copy, run byblock-convention-violation)is unchanged. It is POSIX sh, so it cannot use the bash helper, and its
git ls-filescallsread the index before its
check-ignoredoes. Changing only its ignore check would not stop aplanted fsmonitor.
Related
block-main-checkout-edit.🤖 Generated with Claude Code
https://claude.ai/code/session_01VcupokBnD3fgV5DKj7GeJA