Skip to content

fix(hooks): pass the git overrides to the end-of-turn git-hook entries - #17274

Merged
kyle-sexton merged 3 commits into
mainfrom
fix/16959-hook-child-git-overrides
Nov 18, 2026
Merged

kyle-sexton merged 3 commits into
mainfrom
fix/16959-hook-child-git-overrides

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Closes #16959

Summary

Eight end-of-turn hooks start their plugin's git-hook entry (git-hooks/lint.sh --worktree, or format.sh --worktree for go-format) as a separate bash process: actionlint-check.sh, bash-format.sh, go-format.sh, javascript-format.sh, markdown-format.sh, powershell-format.sh, python-format.sh and spelling.sh. That process never loads hook-utils.sh, so check-lib.sh and the adapters ran git without the overrides, and their ls-files and diff calls read the index. Reading the index starts the command the repository's core.fsmonitor names. As the hub session decided on the issue, the hook now passes the overrides to the child through git's config environment variables.

Fix

  • lib/hook-utils.sh keeps the override list once, in HOOK_GIT_UNTRUSTED_CONFIG (core.fsmonitor=false, core.hooksPath=/dev/null). hook::git_untrusted builds its -c arguments from it, and the new hook::git_untrusted_env exports it as GIT_CONFIG_COUNT / GIT_CONFIG_KEY_n / GIT_CONFIG_VALUE_n. When the caller already set GIT_CONFIG_COUNT, the pairs are appended after the existing ones and none is overwritten. A count that is not a non-negative integer returns 1 and changes nothing (git itself refuses such a count).
  • Each of the eight hooks sources hook-utils.sh in its end-of-turn branch. It runs hook::git_untrusted_env inside the command substitution that starts the entry, so the variables reach only that child. spelling.sh exits right after its entry, so it exports them in its own process.
  • actionlint and powershell-format now carry a hook-utils.sh copy (scripts/shared-copies.txt). scripts/sync-shared-copies.sh regenerated all 24 copies.
  • worktree-add-containment-gate.sh defines _worktree_root_git as hook::git_untrusted. The worktree-root-resolve.sh it sources already calls that hook when it is defined (worktree_root_git). The gate's worktree-root lookups (config --get-all, rev-parse --git-dir) ran plain command git before.
  • In hardcoded-path-patterns.sh, hpp::resolve_scan_root keeps its exec git (one process) and takes its arguments from the same list ("${_HOOK_GIT_UNTRUSTED_ARGS[@]}").
  • One patch fragment per hook-utils.sh carrier (24).

Git versions and paging

  • git help config, ENVIRONMENT (git 2.53.0 on this machine): "If GIT_CONFIG_COUNT is set to a positive number, all environment pairs GIT_CONFIG_KEY_ and GIT_CONFIG_VALUE_ up to that number will be added to the process's runtime configuration ... These environment variables will override values in configuration files, but will be overridden by any explicit options passed via git -c."
  • Git 2.31.0 added these variables. Its release notes (RelNotes/2.31.0.adoc:127-130) say: "Two new ways to feed configuration variable-value pairs via environment variables have been introduced". The ENVIRONMENT section of git-config 2.30.0 lists only GIT_CONFIG and GIT_CONFIG_NOSYSTEM; 2.31.0 adds GIT_CONFIG_COUNT, GIT_CONFIG_KEY_<n> and GIT_CONFIG_VALUE_<n>. An older git does not know them, so the child runs as it did before this change, with no override. That reading was not run against a pre-2.31 git.
  • --no-pager has no configuration-variable form. The child never pages because git pages only when its standard output is a terminal. git help git, --paginate: "Pipe all output into less (or if set, $PAGER) if standard output is a terminal." Each hook starts its entry with standard output on /dev/null (2>&1 >/dev/null, or >/dev/null in spelling.sh). Every git the entry starts therefore writes to that, to a pipe or to a command substitution, never to a terminal.

Verification

  • lib/hook-git.test.sh adds these cases:
    • For each of the eight hooks, a fixture check: the entry run on its own in a repository with a planted core.fsmonitor starts it. This proves the hook case below exercises an index read.
    • The hook's --end-of-turn run, which must not start the planted fsmonitor.
    • A git shim that records GIT_CONFIG_COUNT=2 for the entry's git calls. This proves the entry ran git and received the variables.
    • A case where the caller's own GIT_CONFIG_COUNT=1 pair survives and the overrides follow it.
    • A git argv check on the containment gate's two root lookups.
  • On main: 8 failed, each with "ran the repository's core.fsmonitor". The containment case failed with "2 without" when the gate line was taken out. After the change: 41 passed, 0 failed.
  • scripts/affected-tests.sh --run over the first commit:
    • The eight plugins' hook, end-of-turn, format and lint suites report 0 failed.
    • worktree-add-containment-gate.test.sh cases 40-41 failed with the first attempt. That attempt defined _worktree_root_git in the gate, which makes the legacy-alias helper treat the gate as read-only. The second commit moves the change into worktree-root-resolve.sh instead, and the suite now passes 48/48. worktree-gates-spawn-budget.test.sh passes.
    • Four suites failed only because this worktree had no node_modules installed: check-script-contract (htmlhint missing), graphql-operations (module not found), write-runner-hold-labels and write-runner-never-rules (runner-policy not installed).
  • hardcoded-path-check.test.sh 173/0 and block-github-post-content.test.sh 199/0 after the scan-root change.
  • shellcheck -x clean on every changed shell file; check-changelog-fragments.sh --check passes; the pre-push check-affected passed.
  • Sweep after this PR: no git call in plugins/*/hooks/**, in the libraries hooks source, or in the scripts hooks start runs without the overrides, other than the two items below that the issue comment leaves on purpose. plugins/testing/hooks/judge-lib.sh is not loaded by any hook.

Related

🤖 Generated with Claude Code

kyle-sexton and others added 2 commits November 18, 2026 16:12
Eight end-of-turn hooks start their plugin's git-hook entry with --worktree as a
separate bash process. It never loads hook-utils.sh, so check-lib.sh and the
adapters ran git without the overrides and read the index, which starts the
command the repository's core.fsmonitor names.

hook-utils.sh keeps the override list in HOOK_GIT_UNTRUSTED_CONFIG. Both
hook::git_untrusted (as -c arguments) and the new hook::git_untrusted_env
(as GIT_CONFIG_COUNT / GIT_CONFIG_KEY_n / GIT_CONFIG_VALUE_n, appended after
any pairs the caller set) are built from it. Each of the eight hooks calls
hook::git_untrusted_env in the child's subshell before starting the entry.
actionlint and powershell-format now carry a hook-utils.sh copy.

Refs: #16959

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…an-root probe

worktree-root-resolve.sh, which the worktree-add containment gate sources, ran
its config and rev-parse calls with plain `command git`. It now calls
hook::git_untrusted when hook-utils.sh is loaded and no _worktree_root_git is
defined; the fleet audit's read-only wrapper keeps priority, and the gate's
retired-alias rewrite still runs. hpp::resolve_scan_root keeps its exec git and
takes its arguments from the same override list.

Refs: #16959

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton

Copy link
Copy Markdown
Member Author

Owner of this pull request: the control-hub session for plugin profiles (melodic-software/control-hub#11). It waits on CI Status and the review lanes; the hub reads the reviews and merges. Other sessions: do not push, resolve threads or queue it.

@kyle-sexton
kyle-sexton marked this pull request as ready for review November 18, 2026 21:26
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T21:52:47.450366Z 754f063 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 754f0633b0ac348dd49b59b80ead92a5d1386967: read 27 of 27 changed file(s); 0 finding(s), 0 as inline comments.

Security review: incremental (872952b → 754f063)

I found no security issues in this push. I read all six files on the to-read list, every hunk, in .claude-lane/incremental.diff. The other hook-utils.sh copies are byte-identical to the ones I read. Each one sits at a hooks/ or scripts/ path that already sources this library, so its path does not change what the content does. This lane already reviewed an earlier head, so this review was blocking only: it reports only CRITICAL and IMPORTANT findings.

What I checked

  • hook::git_untrusted_exec, added in lib/hook-utils.sh and its copies. It runs exec git "${_HOOK_GIT_UNTRUSTED_ARGS[@]}" "$@". The override arguments are the same --no-pager -c core.fsmonitor=false -c core.hooksPath=/dev/null list that hook::git_untrusted uses, and the caller's arguments come after them. This push changes nothing else in the library.
  • plugins/guardrails/lib/path-detection/hardcoded-path-patterns.sh:346. The old inline exec git "${_HOOK_GIT_UNTRUSTED_ARGS[@]}" … becomes a call to the new helper inside the same $(...) command substitution. So exec still replaces only the subshell, never the hook process.
    • The new form is safer when the library is missing. Before, an unset array expanded to nothing, and git ran without the overrides. Now an undefined function fails, toplevel comes back empty, and [[ -n "$toplevel" ]] || return 0 returns before any git runs without them.
  • lib/hook-git.test.sh. The test shims now write $ as the octal escape \044 in the printf format string, which removes the SC2016 suppressions. The generated shim is unchanged. This is test code only, with no security surface.

Instruction-surface lens: the only lines this push removes are two # shellcheck disable comments and one inline git call that the helper replaces. They remove no standing instruction, block list or allowlist.

Spend: none. Nothing in this push changes lane runs, models or billing.

critical-findings: 0

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

claude-review: 1 inline finding(s) on 872952b0f177512719a37c1afb51ddf4b2941e46; the summary is in this lane's pull request comment.

claude-lane: claude-review

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed 754f0633b0ac348dd49b59b80ead92a5d1386967: read 27 of 27 changed file(s); 0 finding(s), 0 as inline comments.

Code review (incremental, 872952b → 754f063)

No findings. This lane already reviewed an earlier head, so this pass reported blocking findings only.

I read all 6 files on the to-read list in .claude-lane/incremental.diff. Every other hook-utils.sh copy in the diff has the same 4-line hunk.

What changed

  • New hook::git_untrusted_exec in lib/hook-utils.sh:1023-1025 and its synced copies.
    • It runs exec git "${_HOOK_GIT_UNTRUSTED_ARGS[@]}" "$@", using the same override list as hook::git_untrusted.
    • Its only caller is hpp::resolve_scan_root. That call sits inside $( … ), so exec replaces only the subshell, and the PR keeps its one-process design.
    • 2>/dev/null still applies to the function call.
  • The hpp::resolve_scan_root callers source hook-utils.sh first.
    • The only callers are hardcoded-path-check.sh:208,369 and block-github-post-content.sh:166. Both source the guardrails hook-utils.sh first, and that copy now has the function.
    • content-scan.sh and hardcoded-path-check.test.sh source the patterns library but never call resolve_scan_root.
  • Test shims in lib/hook-git.test.sh:143,164.
    • They now write $ as the printf octal escape \044. Bash's builtin printf expands that in the format string, so the generated shim still reads "$GIT_CONFIG_COUNT", "$*" and "$@".
    • This drops the SC2016 suppressions without a behaviour change.

Prior finding

The loosened-check finding on hardcoded-path-patterns.sh:346 and its siblings at lib/hook-git.test.sh:143/165 is fixed. The incremental diff removes all three # shellcheck disable= lines, and none of the changed files adds a new suppression. The settled thread agrees.

Other checks

  • Loosened-check verdict: fail (the default; the wrapper wrote no loosened_check_verdict: / loosened_check_patterns: line); patterns: 0. No loosened_check_decision_record: line was supplied, so I did not check the citation requirement. The incremental change adds no loosening, so nothing fails under it.
  • Hold: none. No paid-resource or billing change.
  • Embedded text: the PR context, settled threads and prior findings contain no instructions aimed at the lane.
  • Verification: I ran no tests. Any test results in the PR are the author's claim and unverified.

Verifier dropped 0 of 0 candidates.

hpp::resolve_scan_root read hook-utils.sh's override array directly, which
needed an SC2154 suppression. hook-utils.sh now defines
hook::git_untrusted_exec, which execs git with the same arguments, so the scan
root lookup still costs one process and the override list keeps one
definition. The two git shims in lib/hook-git.test.sh write each `$` as the
printf escape \044 in place of a single-quoted literal, so SC2016 has nothing
to flag.

Refs: #16959

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 754f0633b0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit d46e268 Nov 18, 2026
63 checks passed
@kyle-sexton
kyle-sexton deleted the fix/16959-hook-child-git-overrides branch November 18, 2026 22:17
@github-actions github-actions Bot added the merge-path: owner-agent Post-merge accounting record (README.md, Merge paths) label Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-path: owner-agent Post-merge accounting record (README.md, Merge paths)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Turn off config-driven commands on every git ignore check a hook runs

1 participant