Skip to content

fix: chain repository hooks under git -c overrides - #5877

Merged
kunchenguid merged 2 commits into
kunchenguid:mainfrom
FocalFactotum:fm/firstmate-hooks-wrapper-upstream-v1
Sep 27, 2026
Merged

kunchenguid merged 2 commits into
kunchenguid:mainfrom
FocalFactotum:fm/firstmate-hooks-wrapper-upstream-v1

Conversation

@FocalFactotum

Copy link
Copy Markdown
Contributor

Intent

Offer the per-task git hooks wrapper fix upstream as a pull request that resolves #5871: when core.hooksPath reaches git through git -c (GIT_CONFIG_PARAMETERS or GIT_CONFIG_COUNT), the per-task hooks wrapper looks up the repository's real hooks with that injected setting still active, finds itself, and skips the real hooks. A proven fix already exists on the local branch fm/git-hooks-wrapper-guard-fix-v1 at commit 25e38060 (changes to bin/fm-git-strip-ai-trailers.sh and tests/fm-git-strip-ai-trailers.test.sh): the wrapper removes both injected-config channels for the real-hook lookup, and fails instead of silently succeeding when that lookup fails.

What Changed

  • Resolve the repository’s real hooks directory after clearing both injected Git config channels, so wrappers chain project hooks when core.hooksPath is supplied through git -c.
  • Fail the Git operation if the real hooks directory cannot be resolved, instead of silently skipping a project hook.
  • Add regression coverage for guarded pushes and commit hooks across environment and git -c overrides, and document the behavior.

Risk Assessment

✅ Low: The focused change clears both injected Git config channels during the real-hook lookup, fails when lookup fails, and adds behavioral coverage for the reported bypass.

Testing

The focused test passed using real Git commits and pushes. Manual evidence reproduced the skipped guard on the base commit, showed both override channels blocked by the changed wrapper, and confirmed a failed hook lookup exits nonzero. Temporary fixtures were removed and the worktree is clean.

  • Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario Result Live Evidence
A git -c hooksPath push runs the repository's refusing pre-push hook and leaves the remote unchanged ✅ pass live Live hook behavior and before-fix reproduction
A GIT_CONFIG_COUNT hooksPath push runs the repository's refusing pre-push hook and leaves the remote unchanged ✅ pass live Live hook behavior
Child Git commands inherit hooksPath overrides while the repository's pre-push guard still refuses their pushes ✅ pass live bash tests/fm-git-strip-ai-trailers.test.sh
A git -c commit strips the AI trailer and runs the repository's pre-commit hook ✅ pass live bash tests/fm-git-strip-ai-trailers.test.sh
A wrapper that cannot resolve the repository hooks directory exits with an error ✅ pass live Live hook behavior
Evidence: Live hook behavior
CASE git -c core.hooksPath push
repository pre-push refused
error: failed to push some refs to '/var/folders/4d/d_s_7wwx3bgd8_kbtqw88dbh0000gn/T//fm-hooks-live.pSlFlq/remote.git'
push exit=1; guard marker=guard invoked
remote ref=absent
CASE GIT_CONFIG_COUNT core.hooksPath push
repository pre-push refused
error: failed to push some refs to '/var/folders/4d/d_s_7wwx3bgd8_kbtqw88dbh0000gn/T//fm-hooks-live.pSlFlq/remote.git'
push exit=1; guard marker=guard invoked
remote ref=absent
CASE wrapper lookup outside a Git repository
fatal: not a git repository (or any of the parent directories): .git
fm-git-strip-ai-trailers: cannot resolve this repository's hooks directory; refusing to skip its pre-push hook
wrapper exit=1
Evidence: Before-fix reproduction
BASELINE git -c core.hooksPath push
push exit=0
guard marker=missing
remote ref=present

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario Result Live Evidence
A git -c hooksPath push runs the repository's refusing pre-push hook and leaves the remote unchanged ✅ pass live Live hook behavior and before-fix reproduction
A GIT_CONFIG_COUNT hooksPath push runs the repository's refusing pre-push hook and leaves the remote unchanged ✅ pass live Live hook behavior
Child Git commands inherit hooksPath overrides while the repository's pre-push guard still refuses their pushes ✅ pass live bash tests/fm-git-strip-ai-trailers.test.sh
A git -c commit strips the AI trailer and runs the repository's pre-commit hook ✅ pass live bash tests/fm-git-strip-ai-trailers.test.sh
A wrapper that cannot resolve the repository hooks directory exits with an error ✅ pass live Live hook behavior
  • bash tests/fm-git-strip-ai-trailers.test.sh
  • Manual isolated Git pushes using git -c core.hooksPath and GIT_CONFIG_COUNT, with a refusing repository pre-push hook
  • Manual invocation of the installed pre-push wrapper outside a Git repository
  • Manual before-fix push using the base-commit wrapper
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…task hooksPath

The per-task hooks wrappers cleared only the GIT_CONFIG_COUNT override before
looking up the repository's own hooks directory. When core.hooksPath reached git
through git -c (GIT_CONFIG_PARAMETERS), directly or inherited by a child
process, the lookup found the wrapper directory again and exited 0, so the
repository's real hook - such as a pre-push publish guard - never ran and the
push succeeded.

The lookup now ignores GIT_CONFIG_PARAMETERS too, so only the repository's
config files decide its hooks directory, and a failed lookup exits nonzero
instead of skipping the hook. AI-trailer stripping is unchanged.

Fixes kunchenguid#5871
@kunchenguid
kunchenguid merged commit b4561ad into kunchenguid:main Sep 27, 2026
19 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @FocalFactotum — really appreciate you taking the time on this.

Closes #5871 — verified GitHub closing link (Fixes #5871 in commit; GraphQL closingIssuesReferences).

Contract-class: restore — pane hooksPath already promised to chain the repository's real hooks (docs/configuration.md on main). Main tip 5a9880b4 runtime_chain_body only cleared GIT_CONFIG_COUNT* and exited 0 on lookup failure; tip also clears GIT_CONFIG_PARAMETERS for the lookup and fails closed when lookup fails. Happy-path unconfigured behavior unchanged except the broken git -c channel now chains. No new always-on surface.

Inspected tip vs main

  • bin/fm-git-strip-ai-trailers.sh runtime_chain_body: unset GIT_CONFIG_PARAMETERS around git rev-parse --git-path hooks; nonzero exit + stderr when lookup fails.
  • Tests: test_repository_pre_push_runs_on_every_override_channel (env / param / env+param / child-env / child-param) and test_git_c_override_still_strips_and_chains_commit_hooks.
  • Docs: configuration.md notes git -c channel + fail-closed lookup.

VISION

  • One captain, one interface — aligns: silently skipping a project's pre-push hid a guard failure inside machinery.
  • Authority explicit, never inferred — aligns: no consent widening; restores already-promised chain.
  • Scripts own the mechanics, agents own the judgment — aligns: wrapper lookup is deterministic script work.
  • A restart is a non-event — cannot tell: not the defect's axis.
  • Delegation with a spine — aligns: ship/guard hooks must actually run in task panes.
  • The fleet outlives any vendor — aligns: git client-hook chaining is harness-orthogonal.
  • Scope — aligns: launch-time hooksPath hygiene is command-layer, not workshop.

CI green (36302881942) · NM SUCCESS · attestation MATCH ab92d124f832fcd338775c782fe718c6921af410 · MERGEABLE/CLEAN · squash b4561ada4218fd69ff3f6b5b00fd50dbddee88f8. Workflow approvals: none needed (checks already ran). Firstmate flag: no. Security FYI: no.

mehulbhagwani pushed a commit to mehulbhagwani/firstmate that referenced this pull request Sep 27, 2026
* fix(bin): run the repository's own hooks when git -c carries the per-task hooksPath

The per-task hooks wrappers cleared only the GIT_CONFIG_COUNT override before
looking up the repository's own hooks directory. When core.hooksPath reached git
through git -c (GIT_CONFIG_PARAMETERS), directly or inherited by a child
process, the lookup found the wrapper directory again and exited 0, so the
repository's real hook - such as a pre-push publish guard - never ran and the
push succeeded.

The lookup now ignores GIT_CONFIG_PARAMETERS too, so only the repository's
config files decide its hooks directory, and a failed lookup exits nonzero
instead of skipping the hook. AI-trailer stripping is unchanged.

Fixes kunchenguid#5871

* no-mistakes(document): Document git hook chaining and lookup failure behavior
mehulbhagwani pushed a commit to mehulbhagwani/firstmate that referenced this pull request Sep 27, 2026
* fix(bin): run the repository's own hooks when git -c carries the per-task hooksPath

The per-task hooks wrappers cleared only the GIT_CONFIG_COUNT override before
looking up the repository's own hooks directory. When core.hooksPath reached git
through git -c (GIT_CONFIG_PARAMETERS), directly or inherited by a child
process, the lookup found the wrapper directory again and exited 0, so the
repository's real hook - such as a pre-push publish guard - never ran and the
push succeeded.

The lookup now ignores GIT_CONFIG_PARAMETERS too, so only the repository's
config files decide its hooks directory, and a failed lookup exits nonzero
instead of skipping the hook. AI-trailer stripping is unchanged.

Fixes kunchenguid#5871

* no-mistakes(document): Document git hook chaining and lookup failure behavior
mehulbhagwani pushed a commit to mehulbhagwani/firstmate that referenced this pull request Sep 27, 2026
* fix(bin): run the repository's own hooks when git -c carries the per-task hooksPath

The per-task hooks wrappers cleared only the GIT_CONFIG_COUNT override before
looking up the repository's own hooks directory. When core.hooksPath reached git
through git -c (GIT_CONFIG_PARAMETERS), directly or inherited by a child
process, the lookup found the wrapper directory again and exited 0, so the
repository's real hook - such as a pre-push publish guard - never ran and the
push succeeded.

The lookup now ignores GIT_CONFIG_PARAMETERS too, so only the repository's
config files decide its hooks directory, and a failed lookup exits nonzero
instead of skipping the hook. AI-trailer stripping is unchanged.

Fixes kunchenguid#5871

* no-mistakes(document): Document git hook chaining and lookup failure behavior
knowttl pushed a commit to knowttl/firstmate that referenced this pull request Sep 29, 2026
* fix(bin): run the repository's own hooks when git -c carries the per-task hooksPath

The per-task hooks wrappers cleared only the GIT_CONFIG_COUNT override before
looking up the repository's own hooks directory. When core.hooksPath reached git
through git -c (GIT_CONFIG_PARAMETERS), directly or inherited by a child
process, the lookup found the wrapper directory again and exited 0, so the
repository's real hook - such as a pre-push publish guard - never ran and the
push succeeded.

The lookup now ignores GIT_CONFIG_PARAMETERS too, so only the repository's
config files decide its hooks directory, and a failed lookup exits nonzero
instead of skipping the hook. AI-trailer stripping is unchanged.

Fixes kunchenguid#5871

* no-mistakes(document): Document git hook chaining and lookup failure behavior
jredgard added a commit to jredgard/firstmate that referenced this pull request Sep 29, 2026