push-target
The built-in Policy push-target, against commits and pushes to shared branches, lost stashes, merges only people should make: its defaults, its options and a configuration that writes it.
To learn what it guards against and see it at work, read the guide: Git and forge.
Defaults
| Default | Value |
|---|---|
| On by default | no: an entry turns it on |
| Fail mode | closed |
| Timeout | 10000 ms |
| Events | PreToolUse |
| Tools | Bash |
| Agent types | every agent, or as its options set |
Options
| Option | Type | Default | Description |
|---|---|---|---|
allowDryRun | boolean | true | Whether a --dry-run push passes. |
copies | object | {"multiTargetSuffix":"-onto-","worktreeSuffix":"-[0-9]+$"} | The suffixes of a branch's copies. |
deployBranches | string[] | [] | Globs of deploy branches, which the pull request head check leaves alone, beside the project's. |
forgeRemote | string | "origin" | The remote the forge's pull requests live on. |
protectedBranches | string[] | — | The shared branches no push may write to, directly, through the branch's upstream or through push.default=upstream; the default branch of the remote the push names when absent. |
pullRequestHead | object | {"enabled":true,"exempt":["assets/"],"keyPattern":"^([A-Za-z][A-Za-z0-9]*-[0-9]+)","limit":500,"timeoutMillis":5000} | The check that refuses a push to a copy of a branch that already has an open pull request. |
unknownLocation | "allow" | "refuse" | "refuse" | refuse refuses a push that writes the current branch from a folder the guard cannot follow; allow lets it run. |
Example
A configuration that writes every option, a comment above each:
import { defineConfig } from '@microeinhundert/harness-kit';
export default defineConfig({
// The Policy entries, in the order their Decisions merge in.
policies: [
{
// The Policy's name, unique in the configuration; messages and logs name the Policy by it.
id: 'push-target',
// The constructor's options, which it decodes.
options: {
// Whether a `--dry-run` push passes.
allowDryRun: true,
// The suffixes of a branch's copies.
copies: {
// The text that opens the suffix of a branch's copy made for one target, such as `-onto-`
// in `feat-x-onto-release-3`.
multiTargetSuffix: '-onto-',
// The pattern of the suffix a worktree's copy of a branch adds, such as `-[0-9]+$` for
// `feat-x-2`, a copy of `feat-x`.
worktreeSuffix: '-[0-9]+$',
},
// Globs of deploy branches, which the pull request head check leaves alone, beside the
// project's.
deployBranches: ['release/*'],
// The remote the forge's pull requests live on.
forgeRemote: 'origin',
// The shared branches no push may write to, directly, through the branch's upstream or
// through `push.default=upstream`; the default branch of the remote the push names when
// absent.
protectedBranches: ['release/*'],
// The check that refuses a push to a copy of a branch that already has an open pull
// request.
pullRequestHead: {
// Whether the gate runs; it is on unless `false`.
enabled: true,
// Branch prefixes the gate leaves alone, such as `assets/`.
exempt: ['assets/'],
// The pattern of the issue key, read from a branch's last path segment (its first group,
// or the whole match).
keyPattern: '^([A-Za-z][A-Za-z0-9]*-[0-9]+)',
// How many open pull requests the forge's `pr_list` is asked for; an answer that fills
// the limit counts as unknown and passes.
limit: 500,
// How many milliseconds the forge's `pr_list` may take; no answer in time counts as
// unknown and passes.
timeoutMillis: 5000,
},
// `refuse` refuses a push that writes the current branch from a folder the guard cannot
// follow; `allow` lets it run.
unknownLocation: 'refuse',
},
// The name of the kit's Policy constructor that builds the Policy.
use: 'push-target',
},
],
});branch-name
The built-in Policy branch-name, against commits and pushes to shared branches, lost stashes, merges only people should make: its defaults, its options and a configuration that writes it.
stash-safety
The built-in Policy stash-safety, against commits and pushes to shared branches, lost stashes, merges only people should make: its defaults, its options and a configuration that writes it.