git-guard: catch destructive-local ops (reset --hard, clean -f, checkout ., branch -D) #25
Labels
No labels
already-shipped
bug
documentation
duplicate
enhancement
good first issue
help wanted
in progress
invalid
needs-decision
proposal
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: crenshawdev/cadence#25
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Source: skills-analysis session, 2026-07-18 (comparison against Matt Pocock's
git-guardrails-claude-code).Cadence's
git-guard.mjsPreToolUse hook guards push (always ask) and commit on a protected branch (git.on_protected). It does not guard destructive-local commands that can irreversibly wipe uncommitted work:git reset --hard,git clean -f/-fd,git checkout ./git restore .,git branch -D.This is the one class of git command that destroys work with no recovery, and it's currently unguarded.
Do NOT adopt Matt's skill — his is a bash+jq substring-grep blocklist that false-triggers on
echo "git push"and can't tell a dangerous flag combo from a safe one. Cadence's parser is strictly better. This is an extension of the existinggit-guard.mjs, not a replacement.Approach:
gitSubcommands()(or add a sibling check) to recognize the destructive set, flag-aware:resetonly when--hardis present (soft/mixed reset is fine)cleanonly with-f/-fdcheckout/restoreonly when the pathspec is.or--branch -Dgit.on_destructive: ask | deny | allow(defaultask), mirroringon_protected.planningRootwalk-up); silent elsewhere.Benefit: the "oh no" git commands stop and ask before running, so a stray
reset --hardcan't silently vaporize uncommitted work.Scoped for v1.2.0.