Skip to content

fix(guard): check every refspec; add a harmless --self-check - #2

Merged
joepetjr merged 1 commit into
mainfrom
fix/pg-multi-refspec-and-self-check
Oct 1, 2026
Merged

joepetjr merged 1 commit into
mainfrom
fix/pg-multi-refspec-and-self-check

Conversation

@joepetjr

Copy link
Copy Markdown
Contributor

Summary

PG-1 (narrowed) and PG-2 from the portfolio remediation plan, one commit because both units edit the same script and test file.

  • The guard parses git push as argv and checks every refspec of every push on the line. Before, only the first refspec after the remote was read, so git push origin feat/x main and git push origin a && git push origin main got through.
  • Handles quoting, && and ; chains, git -C dir push, option values, --delete across all refspecs, the empty-source deletion refspec, + prefixes and a bare HEAD (now resolved to the current branch). On an unbalanced quote it falls back to a plain split and still checks the command.
  • New --self-check prints a read-only JSON receipt: script SHA-256, effective protected branches and their source, the advisory/fail-open contract, and a registration status of active, registered-script-missing, registered-not-for-bash, not-registered or no-settings (exit 0 only for active). It runs no git, reads no stdin and never pushes.
  • README documents the parsing rules, the unsupported syntax (--all, --mirror, wildcard and tag refspecs, backtick substitution) and the self-check.

Test plan

  • 28 new tests in test_block_direct_integration_push.py; red first: 22 failed before the change.
  • Dispatcher re-run through the slot wrapper: 38 passed in 4.67s (dispatcher re-run through the slot wrapper)
  • The repo's only workflow is leak-scan; no authoring-machine paths are in the changed files.

Acceptance

  • PG-1: quoted input, multiple refs, deletion, option values and the implicit current branch are covered by fixtures; unsupported syntax is listed in the README; protected branches stay env-configurable with the same defaults; the hook stays advisory.
  • PG-2: an absent or unregistered hook is distinguishable from an active one by registration.status and exit code; the check makes no remote call and remote_mutation is always false.

Parse the command line as argv and check every refspec of every push in it, instead of only the first. Add --self-check, a read-only JSON receipt of the protected branches and hook registration state.
@joepetjr
joepetjr merged commit f12ebed into main Oct 1, 2026
1 check passed
@joepetjr
joepetjr deleted the fix/pg-multi-refspec-and-self-check branch October 1, 2026 22:21
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