Skip to content

feat: add pre-push gate requiring remote master - #47

Merged
ryanleecode merged 1 commit into
masterfrom
prepush
Aug 23, 2026
Merged

feat: add pre-push gate requiring remote master#47
ryanleecode merged 1 commit into
masterfrom
prepush

Conversation

@systemfsoftware-maker

Copy link
Copy Markdown
Collaborator

Summary

A push whose branch is forked from a stale or local trunk can now be rejected before it reaches GitHub. This adds a pre-push gate that refuses any push whose refs/heads/* does not contain the remote master tip.

Why not the local master: the local branch lags and is not the source of truth. The gate fetches refs/heads/master from origin, requires it to be an ancestor of every pushed head, and only then allows the push. Force-pushes off a stale trunk stop before they are published.

What changed

  • .husky/pre-push — the hook, installed by husky on pnpm install.
  • scripts/guards/check-remote-master.ts — a Deno guard that runs the check (git-only permissions; no network or env access).
  • husky devDependency, a prepare script, and the arktype deno import the guard needs.

Copied from systemfsoftware/systemfsoftware. The source guard hardcodes refs/heads/main, which would silently allow every push here because comment-checker's default branch is master; the copied guard was adapted to target refs/heads/master so the gate actually enforces.

Deletes, tags, and non-head refs are ignored — only pushed branch heads are gated.

Validation

Exercised the guard directly and through the live husky chain:

  • head contains remote master → allowed (exit 0)
  • head behind remote master → refused with pre-push: behind remote master (exit 1)
  • ref deletion and tag push → ignored (exit 0)
  • the real git push that opened this PR passed the live hook

deno check and deno lint pass on the guard. The cargo gate cannot run on this machine (no cc linker installed); this change touches no Rust.

New concepts

Pre-push gate against the remote head. A git pre-push hook receives the refs being pushed on stdin and can exit non-zero to abort the push. The value is checking the remote trunk, not the local one: query refs/heads/master on the remote and require it be an ancestor of each pushed head, so a branch forked from a stale or local master is refused before it can clobber or force-push the approved trunk. Use it for any repo where a protected trunk must not receive backwards or unreviewed re-bases; skip it when pushes are all fast-forward to a trunk a human reviews in-line.

Copy the systemfsoftware prepush hook: .husky/pre-push delegates to a
Deno guard (scripts/guards/check-remote-master.ts) that refuses any
push whose branch ref does not contain the remote trunk tip. Local
master is never consulted; the guard fetches refs/heads/master and
requires it to be an ancestor of each pushed head. Deletes, tags, and
non-head refs are ignored.

Adapted to this repo's trunk: the source guard hardcodes refs/heads/main,
which is a silent no-op here since comment-checker's default branch is
master; renamed to refs/heads/master so the gate actually enforces.

Wiring: husky ^9.1.7 devDep with a prepare script installs the hook on
pnpm install; arktype@2.2.3 added to scripts/deno.jsonc for the guard.
@ryanleecode
ryanleecode merged commit 67c5552 into master Aug 23, 2026
11 checks passed
@ryanleecode
ryanleecode deleted the prepush branch August 23, 2026 16:49
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.

2 participants