Repository navigation
fix(hooks): skip every git global option in git-guardrails - #4152
Merged
Yeachan-Heo merged 2 commits intoSep 28, 2026
Merged
Yeachan-Heo merged 2 commits into
Yeachan-Heo merged 2 commits into
Conversation
The guardrail skipped only -C and -c before the subcommand, so any other global option was taken for the subcommand and the command passed: `git --no-pager push`, `git -P push`, `git --git-dir=.git reset --hard`, `git --work-tree=. clean -fd` and `git --literal-pathspecs checkout .` all exited 0 with guardrails on. Skip every word that starts with "-" before the subcommand, and let the options that take a separate value (-C, -c, --git-dir, --work-tree, --namespace, --config-env, --attr-source and the hidden --shallow-file) consume it.
Owner
|
Thank you @JayOfTheKeyboard for the fix! The issue was that git-guardrails wasn't properly handling global options that preceded the actual command. The fix correctly ensures that:
✅ All CI checks complete and passing (16 success, 1 skipped) — |
Yeachan-Heo
pushed a commit
to pangpang778/oh-my-claudecode-fork
that referenced
this pull request
Sep 28, 2026
5 of 6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
git-guardrails.mjslooks for the git subcommand after skipping only-C <dir>and-c key=value. Any other global option is taken for the subcommand, so the command passes. WithOMC_GIT_GUARDRAILS=1, fed as a PreToolUse Bash payload ondevat bf4b14d (the script is unchanged on the currentdev, 849d071):git push origin maingit -C . pushgit --no-pager push origin maingit -P pushgit --git-dir=.git reset --hardgit --git-dir .git pushgit --work-tree=. clean -fdgit --no-optional-locks branch -D xgit --literal-pathspecs checkout .--no-pageris common in agent-written git commands, so this is an easy way to miss the guard without trying to. Against a local bare remote, the hook letgit --no-pager push origin HEAD:mainthrough, and the push went through.Fix
In
gitInvocation, every word starting with-before the subcommand is now treated as a global option and skipped. The options that take their value as the next word (-C,-c,--git-dir,--work-tree,--namespace,--config-env,--attr-sourcefromgit help git, plus the hidden--shallow-file) consume that word too, sogit --git-dir push statusis still read asstatus. The=forms and glued-C<path>are single words, so they're covered by the generic skip. The sentence indocs/HOOKS.mdthat listed only-Cand-cis updated to match.The inventory graph is regenerated in a separate commit (
generate:inventory:verifyfails on the source hash otherwise), the same way #4145 did it.Not changed
git --help push/git --version pushare now blocked, although git would only print help or its version.git push --helpwas already blocked before this change, so I kept the parser simple instead of adding a list of terminal options.src/features/lookout/command-parser.tsdoes special-case them, if you'd rather match that.git pforpush) are still not resolved. That's a separate question.Test
The new cases are in
tests/integration/git-guardrails-hook.test.ts: 13 destructive commands that use global options, plus 3 allowed ones (git --no-pager log,git --no-pager push --dry-run,git --git-dir push status).expected +0 to be 2, which means the hook exited 0. The allowed cases pass on the parent too.--git-dir,--work-tree,--namespace,--config-env,--attr-sourceor--shallow-filefrom the value set turns its case red (--git-diralso fails the allowedgit --git-dir push status). Removing-C/-cfrom the set turns 8 existing cases red. Making value options not consume their value turns 15 red. Stopping the skip at the first option that isn't-C/-c(the old behaviour) turns all 13 new destructive cases red.Validation
npx vitest run tests/integration/git-guardrails-hook.test.ts: 111 passednpx vitest runon Linux (Node 22, run on a busy machine): 36 failed / 15050 passed on this branch, against 73 failed / 14998 passed ondev(bf4b14d) run the same way. None of the failures are in the guardrail test. Two files failed only on this branch (cli-config-stop-callback,run-cjs-graceful-fallback), and both pass when run on their own, ondevand on this branch. The rest are team/tmux, timing and Windows-contract tests that fail ondevtoo.npx tsc --noEmitandnpm run lintare clean.npm run generate:inventory:verifyandnpm run plugin:shipping:verifypass.dist/orbridge/changes.