Skip to content

fix: improve git hook safety — fail-closed on missing jq, catch -- separator#2

Open
hobostay wants to merge 1 commit intoevanklem:mainfrom
hobostay:fix/hook-improve-safety
Open

fix: improve git hook safety — fail-closed on missing jq, catch -- separator#2
hobostay wants to merge 1 commit intoevanklem:mainfrom
hobostay:fix/hook-improve-safety

Conversation

@hobostay
Copy link
Copy Markdown

Summary

  • Fail-closed when jq is missing: previously the hook silently allowed all commands if jq was not installed, meaning dangerous git ops would NOT be blocked. Now it exits with code 2 (block) and shows a clear error message.
  • Catch -- separator variants: git checkout -- . and git restore -- . are common ways to discard all working directory changes but were not caught by the existing patterns. Added patterns for both.
  • Removed redundant git clean -fd pattern: git clean -f already matches git clean -fd as a substring, making the -fd entry redundant.

Test plan

  • Verify hook blocks git checkout -- . and git restore -- .
  • Verify hook still blocks all original patterns (git push, git reset --hard, etc.)
  • Temporarily uninstall jq and verify the hook now blocks commands instead of silently allowing them

🤖 Generated with Claude Code

…parator variants

Two safety improvements to block-dangerous-git.sh:

1. Fail-closed when jq is missing: previously the hook silently allowed
   all commands if jq was not installed. Now it blocks commands with a
   clear error message instead.

2. Catch `--` separator variants: `git checkout -- .` and `git restore -- .`
   are common alternatives to discard all working directory changes but were
   not blocked by the existing patterns. Added patterns to catch these.

Also removed the redundant `git clean -fd` pattern since `git clean -f`
already matches it as a substring.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.

1 participant