Skip to content

Block git push --mirror in the pre-bash guard#39

Merged
cgraf78 merged 1 commit into
mainfrom
fix-push-mirror-guard
Jul 2, 2026
Merged

Block git push --mirror in the pre-bash guard#39
cgraf78 merged 1 commit into
mainfrom
fix-push-mirror-guard

Conversation

@cgraf78

@cgraf78 cgraf78 commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Summary

Extend the force-push guard to catch git push --mirror, which
force-overwrites and prunes every remote ref — remote-destructive even
without --force. Follow-up to the +<refspec> fix (#38).

  • add a dedicated _GUARD_GIT_PUSH_MIRROR guard and a --mirror) arm in
    the post-push argument scan
  • give it its own message (the force guard's --force-with-lease advice
    does not fit a mirror push): run it manually if a full mirror is truly
    intended
  • --prune/--all are left out of scope; --mirror is the clear
    remote-destructive gap

Testing

  • new agent-hook-bash-guards-test cases: git push --mirror,
    --mirror origin, and git -C repo push --mirror are blocked with the
    mirror-specific message; normal pushes, +refspec, --force-with-lease,
    and -u are unaffected
  • verified red-green: removing the --mirror) arm lets --mirror through
    (exit 0)
  • full suite green (./test/agentguard-test: all suites 0 failed);
    checkrun lint clean

Summary

Extend the force-push guard to catch `git push --mirror`, which
force-overwrites and prunes every remote ref — remote-destructive even
without `--force`. Follow-up to the `+<refspec>` fix (#38).

- add a dedicated `_GUARD_GIT_PUSH_MIRROR` guard and a `--mirror)` arm in
  the post-`push` argument scan
- give it its own message (the force guard's `--force-with-lease` advice
  does not fit a mirror push): run it manually if a full mirror is truly
  intended
- `--prune`/`--all` are left out of scope; `--mirror` is the clear
  remote-destructive gap

Testing

- new `agent-hook-bash-guards-test` cases: `git push --mirror`,
  `--mirror origin`, and `git -C repo push --mirror` are blocked with the
  mirror-specific message; normal pushes, `+refspec`, `--force-with-lease`,
  and `-u` are unaffected
- verified red-green: removing the `--mirror)` arm lets `--mirror` through
  (exit 0)
- full suite green (`./test/agentguard-test`: all suites 0 failed);
  `checkrun lint` clean
@cgraf78 cgraf78 merged commit acadbbd into main Jul 2, 2026
6 checks passed
@cgraf78 cgraf78 deleted the fix-push-mirror-guard branch July 2, 2026 12:42
cgraf78 added a commit that referenced this pull request Jul 2, 2026
Summary

Extend the push guard to catch `git push --prune`, which deletes remote
refs that have no local counterpart — remote-destructive. Follow-up to
the `+<refspec>` (#38) and `--mirror` (#39) guards.

- add a dedicated `_GUARD_GIT_PUSH_PRUNE` guard and a `--prune)` arm,
with
  its own message
- bare `--all` is intentionally NOT guarded: it only pushes branches and
  is destructive only combined with `--force`, which is already caught

Testing

- new `agent-hook-bash-guards-test` cases: `git push --prune ...` is
  blocked with the prune-specific message; bare `git push --all origin`
  stays allowed
- verified red-green: removing the `--prune)` arm lets `--prune` through
  (exit 0)
- full suite green (`./test/agentguard-test`: all suites 0 failed);
  `checkrun lint` clean
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